/**
  ******************************************************************************
  * @file    BP.c
  * @author  测试1组（houtiezhu）
  * @version v0
  * @date    09-07-2019
  *
  * @verbatim
  **/
/* Includes ------------------------------------------------------------------*/

#include "define.h"
#include "disp.h"
#include "power.h"
#include "clk.h"
#include "gpio.h"
#include "time.h"
#include "uart.h"
#include "spk.h"
#include "flash.h"
#include "adc.h"
#include "algo.h"
#include "bp.h"
#include "func.h"
#include "op.h"
#include "pwm.h"

uint32 delaytest=100000;
//extern  u32 MemBack[2048/4];

uint16  PulseMeanEnd;
//uint8   MemoryEndIndex;
uint8   WHOLevel;
uint8  SLevel;
uint8   LastDIA;
uint16  LastSYS;
uint16  ShowPressCount;
uint32 x,y,z;
uint8 noactioncount;
uint8 first10flag,first1flag;
uint8 TestValue;
uint8 BPTestFlag,CuffFlag,MoveFlag; //bit
uint16  SetPressureVw;
uint8 VoiceType2;
uint8 VoiceLevel;
uint16   EEPROMin;
uint8  NoEndFlag;
uint8 ShowBTLevel,BTLevel;
uint8 USBFlag=0;
uint8   AverageSet;
uint16   MemorySet;   		 	//memory set
uint8	MemorySetType;
uint16  SysMeanEnd;
uint16 	PressureCountw;
uint8 AutoKeyCount[2];
uint8 WorkMode;
uint8   validcount;
uint16  LeakageP[10];
uint16  PressureBackup;

unsigned int	MemoryIndexBackup=0;
unsigned int	MemoryEndIndexBackup=0;

volatile union byte_bit 	mtemp0c,mtemp1c;
volatile union byte_bit  KeyModeFlag;
volatile union byte_bit	MeasureStateFlag;
volatile union byte_bit		SystemSetFlag;
volatile union byte_bit		SystemSetFlag2;
volatile union byte_bit		SystemSetFlag3;
volatile union byte_bit		SystemSetFlag4;
volatile union byte_bit		SystemSetFlag5;
volatile union byte_bit		SystemSetFlag6;

volatile union byte_bit		SysStateFlag;
volatile union byte_bit		SysStateFlag2;


volatile union byte_bit		UserSetFlag;

volatile union word_data		AutoOffTime2 ;

volatile union word_data  	OscilloSignal;
volatile union byte_bit 		TimeBase;
volatile union byte_bit		WatchTime;
volatile union byte_bit		Year;
volatile union word_data		AutoOffTime2 ;

volatile union word_data 	SensorCount ;
volatile union word_data 	PressuremmHg;
volatile union word_data 	SensorCounta;
volatile union word_data		OscilloSignal;
volatile union dword_data	Math;
volatile union byte_bit 		STATEFlag1;
volatile union byte_bit		OneShotFlag;
volatile union word_data		ZeroCount;
volatile union dword_data	TemplateValue;
volatile union byte_bit		KeyFlag;

volatile union word_data		A1w ;
volatile union word_data 	B1w ;
volatile union word_data 	C1w ;






uint8 VoiceType2;

uint8 i;
uint8   N;

void Bp_Work(void)
{
	#if 1
#if 22
ShowAllIcon();
    while (1)
    {
        /* code */
    }
    
#endif
    delay(5);
	if(VoiceType==13&&(VoiceType2==1||VoiceType2==3))
	{
		SoundLevelSet();
	}
    if (VoiceType==1&&VoiceType2==3)
    {
        swit_china_eng_malay(e_voice_c_e_ma_switch);//中语英语马来西亚语切换
        volume_adjus_china_eng_malay(VoiceLevel);//中语英语马来西亚语音量调节
    }
	if(!KEY_POWER&&!KEY_TIME)
		{
			IsCALMode=1;
			IsPowerOn = 1;
		}
	if(!KEY_POWER)
		{
			IsCalibrate=1;
			IsPowerOn = 1;
		}

	delaytest=1500000;
	if(KeyNumber==8)
	{
		ShowAllIcon();
		nopdelay();
		if(!KEY_POWER&&!KEY_TIME)
			{
				IsCALMode=1;
				IsPowerOn = 1;
			}
		if(!KEY_POWER)
			{
				IsCalibrate=1;
				IsPowerOn = 1;
			}
	}

	if(IsCALMode)
		{
			AutoCALMode();
			goto STARTUP;
		}
	if(!IsCalibrate)
		{
			checkmemorybank();
			if(KeyNumber!=8)
			{
				ShowAllIcon();
				nopdelay();
			}
			if(!NoTimeSet)
			{
				checkeeprom();
				delay(42);
				DarkAllIcon();
				if(!NoTimer)
					{
						if(ThreeKeyFlag) TimeSetThreeKey();
						else
						{
							if(KeyNumber==12) {IsPowerOn=1;goto ThreeKeyMode;}
							TimeSetTwoKey();
						}
						showdate();
						showtime();
						TimePointIconOn;
						delay(64);
					}
			}
		}
STARTUP:
	if(UartType!=5||WorkMode==0)
	{
		if(!IsPowerOn)   tostopmode();
	}
	else
	{
		 	InitialLoop();
			DarkAllIcon();
		 	PUMPPWM_DIS;
		 	zerotracing();
		 	RXIEnable;
		 	BTFlag=0;
		 	while(!BTFlag&&KEY_POWER);
		 	if(BTFlag) goto StartTest;
	}
	IsPowerOn=1;
	if(UartType==4&&BTFlag)
	{
		InitialLoop();
		ShowAllIcon();
		delay(110);
		DarkAllIcon();
		goto StartTest;
	}

	if(IsCalibrate)  													//Calbibrate mode
		{
			InitialLoop();
			IsCALMode=1;
			mmHgkPaFlag=1;
			DarkAllIcon();
//			DisplayHalfByte(0x05,SYSHundred);			//S
//			DisplayHalfByte(0x18,SYSTen);					//U
//			DisplayHalfByte(0x0a,SYSSingle);			//a

			DisplayHalfByte(0x05,SYSTen);			//S
			DisplayHalfByte(0x18,SYSSingle);					//U
			DisplayHalfByte(0x0a,MemorySetSingle);			//a
			DisplayHalfByte(0x01,DIATen);					//1
			kPaPointDIAIconOn;										//.
			DisplayHalfByte(0x00,DIASingle);			//0
			LCD5bitDisplayT(AA1);
			delaytest=750000;
			nopdelay();
			//OutRed=1;
			OutRedOn;
			if(KEY_POWER) IsCALMode=0;
			DarkAllIcon();
			DisplayToSYSDIA(VerMonth,1);
			DisplayToSYSDIA(VerDay,2);
			DisplayToPUL(MemorySet);							//memory set
			if(UartType==6) delaytest=2250000;
			nopdelay();
			//OutGreen=0;
			OutGreenOff;
			if(KEY_POWER) IsCALMode=0;
			DarkAllIcon();
			DisplayToSYSDIA(SystemSetFlag.b,1);		//paramater1
			DisplayToSYSDIA(SystemSetFlag2.b,2);	//paramater2
	//		DisplayToPUL(SystemSetFlag3.b);			//paramater3
			DisplayToPUL(AverageSet);				//paramater3
			delay(85);
			//OutRed=0;
			OutRedOn;
			//OutGreen=1;
			OutGreenOn;
			if(KEY_POWER) IsCALMode=0;
			DarkAllIcon();

			DisplayHalfByte(0xc,SYSTen);			//C
			DisplayHalfByte(0x17,SYSSingle);			//-
		//	DisplayHalfByte(0x17,MemorySetSingle);		//-
			if(IsCALMode&&(!KEY_TIME||(KeyNumber==1)))
				{
					AutoCALMode();
					goto STARTUP;
				}
			do{}while(!KEY_POWER);
			//for(i=0;i<5;i++) CheckBatteryCOM();
			CheckBatteryCOM();
			BB=POWER | VALVE;
			iocontrolon();
			delay(10);
			IsCalibrate=1;
			if(!NoTimer){showtime();showdate();TimePointIconOn;}
			zerotracing();

			functionOKFlag=0;
			SendRomFlag=0;
			RXIEnable;
			BTTestMode=0;
			do
					{
						if(functionOKFlag)
						{
							savefunction();
							functionOKFlag=0;
							sendfunction();
						}
						if(SendRomFlag)
						{
							sendrom();
							SendRomFlag=0;
						}

						if(BTTestMode==1)
						{
							if(T250ms)
							{
								if(BTIconEnable)
								{
									BTIconOn;
								}
									DisplayHalfByte(0x10,SYSHundred);
									DisplayHalfByte(0x19,SYSTen);
									DisplayHalfByte(0x1a,SYSSingle);
							}
							else
							{
								if(BTIconEnable)
								{
									BTIconOff;
								}
									DisplayHalfByte(0x10,SYSHundred);
									DisplayHalfByte(0x10,SYSTen);
									DisplayHalfByte(0x10,SYSSingle);
							}
						}
						else if(BTTestMode==2)
						{
								if(BTIconEnable)
								{
									BTIconOn;
								}
									DisplayHalfByte(0x10,SYSHundred);
									DisplayHalfByte(0x19,SYSTen);
									DisplayHalfByte(0x1a,SYSSingle);
						}
						else if(BTTestMode==3)
						{
								if(BTIconEnable)
								{
									BTIconOn;
								}
									DisplayHalfByte(0xE,SYSHundred);
									DisplayHalfByte(0xB,SYSTen);
									DisplayHalfByte(0xB,SYSSingle);
						}

						if (T125ms == 0) OneShotDC = 0;
						else
							{
								if (OneShotDC == 0)
									{
										OneShotDC = 1;
										calpressure();
										deflate();
										Calshowpres();
										CheckBatteryCOM();
									}
							}
						if(!NoTimer)
							{
								showtime();
								showdate();
								flashtimepoint();
							}
						delay(1);
						if(KeyNumber==3||KeyNumber==2||KeyNumber==4||KeyNumber==7||KeyNumber==9||KeyNumber==10)//KEYNUMBER=5时触摸按键模式
						{
							if(!KEY_MEMORYUP||!KEY_MEMORYDOWN||!KEY_TIME) break;
						}
					}while(KEY_POWER&&IsPowerOn);
			if(!KEY_POWER)
				{
					AutoOffTimew=0;
					while(!KEY_POWER)
					{
						if(AutoOffTimew>150)
						{
							LifeTest();
							break;
						}
					}
					BB=VALVEOFF;
					iocontroloff();
					DarkAllIcon();
				}
			if(!KEY_TIME)
				{
					AutoOffTimew=0;
					while(!KEY_TIME)
					{
					}
					IDbuffer.b = MemorySet;
					writeFULLmemorybank();
				}
			if(!KEY_MEMORYUP||!KEY_MEMORYDOWN)
				{
					AutoOffTimew=0;
					while(!KEY_MEMORYUP||!KEY_MEMORYDOWN)
					{
						if(AutoOffTimew>100&&LinearValveFlag)
						{
							TestValve();
							goto EXIT;
						}
					}
					LifeTest();
				}
				EXIT:
			IsCalibrate=0;
			delay(20);
			checkmemorybank();
			ShowAllIcon();
			delay(128);
			checkeeprom();
			DarkAllIcon();
			InitialLoop();
			IsPowerOn=0;
			goto STARTUP;
		}
	//*******************************************************************************
	if(AlarmClock&&AlarmFlag&&KEY_TIME&&KEY_USER&&KEY_MEMORYUP&&KEY_MEMORYDOWN&&KEY_POWER)	//闹钟
	{
		InitialLoop();
		AlarmFlag=0;
		AutoOffTimew=0;
		KeyIn=1;
		while(KeyIn&&AutoOffTimew<3000)
		{
			showtime();
			showdate();
			TimePointIconOn;
			ADOKFlag=0;
			while(!ADOKFlag);

			if(VoiceType==13)
			{
				N=AutoOffTimew%50;
				if(N==0||N==10||N==20)
				{
					SoundOff2(0xf3);
				}
			}
			else
			{
				N=AutoOffTimew%50;
				if(N<=6) {BUZZER_EN;}
				else if(N<=9) {BUZZER_DIS;}
				else if(N<=15) {BUZZER_EN;}
				else if(N<=18) {BUZZER_DIS;}
				else if(N<=24) {BUZZER_EN;}
				else {BUZZER_DIS;}
			}
		}
		BUZZER_DIS;
	}
	//*******************************************************************************
	if(!CHRG||!FULL)	//充电或插入USB
	{
		USBFlag=1;
		InitialLoop();
		USBFlag=0;
		RXIEnable;
		BTFlag=0;
		if(KEY_TIME&&KEY_USER&&KEY_MEMORYUP&&KEY_MEMORYDOWN&&KEY_POWER)
		{
			if(PowerType)
			{
				//LCD_Init();

				UserSARADC_LBT_Init();//ADC_Meas_Battery_Init();
				UserLCD_Init();
				UserSARADC_LBT_Init();
				delay(2);
				//LBTIconOn;
				LedOn;
				if(BPLevelType!=5)OutGreenOn;// OutGreen=1;
				AutoOffTimew=0;
			}
			while(KEY_TIME&&KEY_USER&&KEY_MEMORYUP&&KEY_MEMORYDOWN&&KEY_POWER)
			{
				if(PowerType==1) //带锂电充电
				{
					if(AutoOffTimew>150)
					{
						LedOff;
						OutGreenOff;
						//OutGreen=0;

					}

					if (T250ms == 0)
					{
						if (OneShot == 1)
						{
							BTLevel=1;
							/*
							TemplateValueLong=SensorCountw;
							TemplateValueLong*=792;
							TemplateValueLong/=32768;
							*/
							CheckBatteryADC();
							if(TemplateValueLong>390) BTLevel=2;
							if(TemplateValueLong>398) BTLevel=3;
							if(TemplateValueLong>405) BTLevel=4;
							if(TemplateValueLong>413) BTLevel=5;

							ShowBTLevel++;
							if(ShowBTLevel<BTLevel) ShowBTLevel=BTLevel;
							if(ShowBTLevel>6) ShowBTLevel=BTLevel;
							if(!FULL) ShowBTLevel=6;
							ShowBTBar();

							OneShot=0;
						}
					}
					else
					{
							if (OneShot == 0)			// if one shot flag = 0 then
								{
										OneShot = 1;		// set on shot flag = 1
								}
					}
				}

				if(BTFlag)
				{
					InitialLoop();
					goto StartTest;	//USB开始测量
				}

				if(SendMemoryFlag)
				{
					SendAllMemoryData();
				}

					if(CHRG&&FULL) 	//拔出USB
					{
						delay(4);
						if(CHRG&&FULL)
						{
							NoEndFlag=1;
							IsPowerOn=0;
							goto STARTUP;
						}
					}
			}
		}
	}
	//*******************************************************************************
	if(!KEY_USER&&KeyNumber==10)
	{
		InitialLoop();
		while(!KEY_USER);
		keydelay();
		goto BTDO;
	}
   	if(!KEY_USER&&TwoUser)
   		{
   			InitialLoop();
				if(KeyNumber==7) goto MEM;
   			ShowAllIcon();
   			while(!KEY_USER);
   			delay(20);
				DarkAllIcon();
				do								//设定UserA及userB
				{
					UserABDisplay();
					AutoOffTimew = 0;
					do{
						delay(1);
						if(AutoOffTimew > AUTOOFFTIME&&!AllTimeFlag){goto UserSetOver;}
						}while(KEY_USER&& KEY_POWER);

					if(!KEY_USER)
						{
							if(UserA==1)
								{
									UserA=0;
								}
							else{UserA=1;}
							UserABDisplay();
							while(!KEY_USER);
							keydelay();
						}
				}while(KEY_POWER);
UserSetOver:
				SaveSet();
				IsPowerOn=0;
				goto STARTUP;
   		}
	//*******************************************************************************
	if(KeyNumber!=6&&KeyNumber!=8)//触摸按键模式不响应
	{
KEYDETECT:
	if(!KEY_MEMORYDOWN||!KEY_MEMORYUP)
		{
			InitialLoop();
			if(KeyNumber==4)
			{
				if(!KEY_MEMORYDOWN)
				{
					UserABDisplay();
					while(!KEY_MEMORYDOWN);
					keydelay();
					do								//设定UserA及userB
					{
						UserABDisplay();
						AutoOffTimew = 0;
						do{
							delay(1);
							if(AutoOffTimew > AUTOOFFTIME&&!AllTimeFlag){goto UserSetOver;}
							}while(KEY_MEMORYDOWN&& KEY_POWER);

						if(!KEY_MEMORYDOWN)
							{
								if(UserA==1)
									{
										UserA=0;
									}
								else{UserA=1;}
								UserABDisplay();
								while(!KEY_MEMORYDOWN);
								keydelay();
							}
					}while(KEY_POWER);
					SaveSet();
					IsPowerOn=0;
					goto STARTUP;
				}
			}
MEM:
			MemoryChangeFlag=0;
			tomemorykeyin();//记忆
			if(SetKeyFlag&&(KeyNumber==11||KeyNumber==12)) goto DELMEM;
			if(KeyNumber==7)
			{
				if(MemoryChangeFlag)
				{
					if(UserA) UserA=0;
					else UserA=1;
					if(VoiceEnable) SoundOff();
					goto MEM;
				}
			}
			IsPowerOn=0;
			goto STARTUP;
		}
	//*******************************************************************************
	//*******************************************************************************
	if(!KEY_TIME)
		{
			InitialLoop();
			if(ThreeKeyFlag) goto ThreeKeyMode;
			ShowAllIcon();
			AutoOffTimew=0x0000;
			do{
					if(AutoOffTimew>150){goto ThreeKeyMode;}
				}while(!KEY_TIME);
			delay(32);
			tomemorykeyin();
			if(SetKeyFlag&&(KeyNumber==11||KeyNumber==12)) goto DELMEM;
			IsPowerOn=0;
			goto STARTUP;
ThreeKeyMode:
			if(SetMode2)
			{
				AutoOffTimew=0;
				while(!KEY_TIME&&AutoOffTimew<150);
				if(AutoOffTimew>=150)
				{
					DarkAllIcon();
					mmHgKpaSetDisplay();
					while(!KEY_TIME);
					keydelay();
					if(VoiceType==12) SoundNoWait(0xC3);
					do								//设定UserA及userB
					{
						mmHgKpaSetDisplay();
						AutoOffTimew = 0;
						do{
							delay(1);
							if(AutoOffTimew > AUTOOFFTIME&&!AllTimeFlag){goto UserSetOver;}
							}while(KEY_MEMORYUP&& KEY_POWER&& KEY_TIME);

						if(!KEY_MEMORYUP)
							{
								if(mmHgkPaFlag==1)
									{
										mmHgkPaFlag=0;
									}
								else{mmHgkPaFlag=1;}
								mmHgKpaSetDisplay();
								while(!KEY_MEMORYUP);
								keydelay();
								if(mmHgkPaFlag==0)
								{
									if(VoiceType==12) SoundNoWait(0xE3);
								}
							}
					}while(KEY_POWER&&KEY_TIME);
					SaveSet();
					while(!KEY_POWER||!KEY_TIME);
					keydelay();
					if(VoiceType==12) SoundCommand(0xC4);
					IsPowerOn=0;
					goto STARTUP;
				}
			}
			if(KeyNumber==11)
			{
				AutoOffTimew=0;
				while(!KEY_TIME&&AutoOffTimew<150);
				if(AutoOffTimew>=150)
				{
					DELMEM:
					if(KeyNumber==11) Key11Clr();
					else Key12Clr();
					IsPowerOn=0;
					goto STARTUP;
				}
			}
			totimekeyin();//用户设置
			if(MemoryKeyFlag) goto MEM;
			if(KeyNumber==11&&SetKeyFlag) goto DELMEM;
			IsPowerOn=0;
			goto STARTUP;
		}
	}
	//*******************************************************************************
	if(!KEY_POWER)
		{
			InitialLoop();
			ShowAllIcon();
			AutoOffTimew=0;
			KeyFlag.b=0;
			AutoTestFlag=0;
			if(KeyNumber==1)
			{
				while(!KEY_POWER)
				{
					if(AutoOffTimew>150)	//长按3秒进入记忆
					{
						ONEKEYMEM:
						tomemorykeyin();
						if(KEY_POWER) {IsPowerOn=0;goto STARTUP;}
						if(AutoOffTimew>149)
						{
							AutoOffTimew=0;
							if(UnitSetEnable) unitsetonekey();	//长按6秒设定单位
							else
							{
								while(!KEY_POWER&&AutoOffTimew<200);
								if(AutoOffTimew<200)
								{
									goto ONEKEYMEM;
								}
							}
							if(KEY_POWER) {IsPowerOn=0;goto STARTUP;}
							if(AutoOffTimew>199)		//长按10秒删除记忆
							{
								DarkAllIcon();
								DisplayHalfByte(0xc,DIATen);
								DisplayHalfByte(0x13,DIASingle);
								while(!KEY_POWER);
								keydelay();
								AutoOffTimew=0;
								do{delay(1);}while(KEY_POWER&&(AutoOffTimew<500));	//等待10秒
								if(AutoOffTimew>499) {IsPowerOn=0;goto STARTUP;}
								AutoOffTimew=0;
								while(!KEY_POWER&&(AutoOffTimew<150));	//长按3秒不删除
								if(AutoOffTimew>149) {IsPowerOn=0;goto STARTUP;}
								CLRMemoryBank();
								for(N=0;N<3;N++)
								{
									DarkAllIcon();
									delay(16);
									DisplayHalfByte(0xc,DIATen);
									DisplayHalfByte(0x13,DIASingle);
									delay(16);
								}
								AutoOffTimew=0;
								do{delay(1);}while(KEY_POWER&&(AutoOffTimew<500));		//删除后等待10秒
								AutoOffTimew=0;
								do{delay(1);}while(!KEY_POWER&&(AutoOffTimew<500));
								if(AutoOffTimew>499)
								 {
									DarkAllIcon();
									MemoryIconOn;
									DisplayHalfByte(0x16,MemorySetTen); //n
									DisplayHalfByte(0x14,MemorySetSingle);//o
									while(!KEY_POWER);
									keydelay();
									AutoOffTimew=0;
									do{delay(1);}while(KEY_POWER&&(AutoOffTimew<500));
								}
								IsPowerOn=0;
								goto STARTUP;
							}
						}
						IsPowerOn=0;
						goto STARTUP;
					}
				}
			}
			else
			{
				AutoOffTimew=0;
				while(!KEY_POWER)
				{
					if(!KEY_POWER&&!KEY_TIME&&UartType==5)
					{
						AutoOffTimew=0;
						while(!KEY_POWER&&!KEY_TIME)
						{
							if(AutoOffTimew>150)
							{
								DarkAllIcon();
								if(WorkMode==0)
								{
									WorkMode=1;
									DisplayHalfByte(1,DIASingle);
								}
								else
								{
									WorkMode=0;
									DisplayHalfByte(0,DIASingle);
								}
								EEPROMin=0x1FF;
								outbyte[0]=WorkMode;
								outbyte[6]=0xac;
								writeM24L16();
								while(!KEY_POWER||!KEY_TIME);
								keydelay();
							}
						}
					}
					if(KeyNumber==6)
					{
						if(AutoOffTimew>250)
						{
							DarkAllIcon();
							showtime();
							showdate();
							TimePointIconOn;
							while(!KEY_POWER);
							keydelay();
							AutoOffTimew=0;
							while((AutoOffTimew<AUTOOFFTIME||AllTimeFlag)&&KEY_POWER)
							{
								delay(1);
								if(SecondFlag)
								{
									SecondFlag=0;
									showtime();
									showdate();
									TimePointIconOn;
								}
								if(!KEY_MEMORYDOWN||!KEY_MEMORYUP||!KEY_TIME) goto KEYDETECT;
							}
							IsPowerOn=0;
							goto STARTUP;
						}
					}
						if(!KeyError&&UartType!=5)
						{
							if(!Key1)
							{
								if(!KEY_TIME)
								{
									Key1=1;
									while(!KEY_TIME);
									keydelay();
								}
								if(!KEY_MEMORYUP)
								{
									KeyError=1;
								}
							}
							else if(!Key2)
							{
								if(!KEY_TIME)
								{
									KeyError=1;
								}
								if(!KEY_MEMORYUP)
								{
									Key2=1;
									while(!KEY_MEMORYUP);
									keydelay();
								}
							}
							else if(!Key3)
							{
								if(!KEY_TIME)
								{
									Key3=1;
									AutoTestFlag=1;
									while(!KEY_TIME);
									keydelay();
									break;
								}
								if(!KEY_MEMORYUP)
								{
									KeyError=1;
								}
							}
						}
				}
			}
			keydelay();
			while(!KEY_POWER);
			if(KeyNumber==8)
			{
				AutoOffTimew=0;
				while(AutoOffTimew<150&&KEY_POWER)
				{
					if(!KEY_MEMORYUP||!KEY_TIME) goto KEYDETECT;
				}
				if(AutoOffTimew>149)
				{
					IsPowerOn=0;
					goto STARTUP;
				}
				AutoOffTimew=0;
				while(!KEY_POWER)
				{
					if(AutoOffTimew>100)
					{
						IsPowerOn=0;
						goto STARTUP;
					}
				}
				keydelay();
				DarkAllIcon();
			}
			if(KeyNumber!=8)
			{
				AutoKeyCount[0]=0;
				AutoKeyCount[1]=0;
				AutoOffTimew=0;
				while(AutoOffTimew<75)
				{
					if(!KEY_POWER)
					{
						AutoKeyCount[0]++;
						while(!KEY_POWER)
						{
							if(AutoOffTimew>=75) break;
						}
						delay(8);
					}
				}
			}
			DarkAllIcon();
			IsPowerOn=1;

			if(!AutoTestFlag&&BTEnable&&((UartType==1||UartType==6)||(UartType==4&&CHRG&&FULL))&&(KeyNumber!=10))
			{
BTDO:
				//BT_POWER=0;
//				BT_POWER_Off;
				AutoOffTimew=0x0000;
				BTFlag=0;
				SendMemoryFlag=0;
				RXEnable;
				RXIEnable;
				do{

						if(UartType!=6)
						{
							if(T250ms == 0)
								{
									if (OneShot == 1)
										{
											OneShot = 0;
											if(BTIconEnable) BTIconOn;
											else
											{
												DisplayHalfByte(0x19,DIATen);			//B
												DisplayHalfByte(0x1a,DIASingle);		//T
											}
										}
								}
							else
								{
									if (OneShot == 0)
										{
											OneShot = 1;
											if(BTIconEnable) BTIconOff;
											else
											{
												DisplayHalfByte(0x10,DIATen);			//B
												DisplayHalfByte(0x10,DIASingle);		//T
											}
											Rs232_SendByte(0xA5);
										}
								}
						}
						else
						{
							showtime();
							showdate();
							flashtimepoint();
						}

						if(KeyNumber==10&&!KEY_USER)//蓝牙键
							{
								IsPowerOn=0;
							}

							if(AutoOffTimew>AUTOOFFTIME&&!AllTimeFlag) break;
							delay(1);
					}while(KEY_POWER&&!BTFlag&&!SendMemoryFlag&&IsPowerOn);     //120S没有BT信号就关机.

				if(SendMemoryFlag)
				{
					SendAllMemoryData();
					IsPowerOn=0;
					goto STARTUP;
				}

				if(!KEY_POWER)
					{
						while(!KEY_POWER);
						keydelay();
						goto StartTest;
					}
				if((AutoOffTimew>AUTOOFFTIME&&!AllTimeFlag)||(!IsPowerOn))
					{
						IsPowerOn=0;
						goto STARTUP;
					}
				else
					{
						IsPowerOn=1;
					}
			}
		}
 	else
		{
			IsPowerOn=0;
			goto STARTUP;
		}
/*******************************************************************************/
StartTest:
	LBTCount=0;
	RXIDisable;
	BTFlag=0;
	DarkAllIcon();
	//if(ConnectFlag&&BTIconEnable) BTIconOn;
 	if(!NoTimer){showtime();showdate();TimePointIconOn;}
	BB=POWER;
	iocontrolon();
	CheckBatteryADC();
	delay(10);
	for(i=0;i<5;i++) {if(IsPowerOn) CheckBatteryCOM();}
	if (IsPowerOn == 1)  	zerotracing();
	if (IsPowerOn == 0)
	{
		if(MemoryKeyFlag) goto MEM;
		if(KeyNumber==11&&SetKeyFlag) goto DELMEM;

		if(SendMemoryFlag)
		{
			SendAllMemoryData();
			IsPowerOn=0;
			goto STARTUP;
		}
		if(BTFlag||AutoTestFlag)
		{
			IsPowerOn=1;
			InitialLoop();
			goto StartTest;
		}

		goto STARTUP;
	}
	BUZZER_EN;
	delay(32);
	BUZZER_DIS;

	if(VoiceEnable==1)
	{
		if(VoiceType==1)
		{
			if((VoiceType==1) && (VoiceType2==2))	//20230508	CN+MD
			{
				SoundCommand(0xC0);	//Place the cuff at the same level as your heart, don`t move and keep quiet
			}
            else if(VoiceType==1&&VoiceType2==3)
            {
                VoiceStop=0;
                volume_adjus_china_eng_malay(VoiceLevel);//中语英语马来西亚语音量调节
                SoundCommand(0xc0);//C0H 请保持安静
                if(!VoiceStop)SoundCommand(0xc1);//C1H 现在准备开始测量血压
            }
			else
			{
				SoundCommand(0xD4);

			}
		}
		else if(VoiceType==14)
		{
			VoiceStop=0;
			SoundCommand(0xF8);
			if(!VoiceStop) SoundCommand(0xF9);
			if(!VoiceStop) SoundCommand(0xFB);
		}
		else if((VoiceType>=2&&VoiceType<=4) || (VoiceType==10))	//Khmer
		{
			SoundCommand(0x80);	//Attention please,Please keep silent and relax keep the cuff at heart level
		}
		else if(VoiceType==5||VoiceType==7)
		{
			SoundCommand(0xb0);
		}
		else if(VoiceType==6)
		{
			SoundCommand2(0xD4);
		}
		else if(VoiceType==8&&VoiceFlag<5)
		{
			SoundFive();
			SoundCommand2(0xC1);
		}
		else if(VoiceType==9)
		{
			VoiceStop=0;
			SoundCommand(0xF3);
			if(!VoiceStop) SoundCommand(0xC2);
		}
		else if(VoiceType==11)
		{
			SoundCommand2(0xC1);
		}
		else if(VoiceType==12)
		{
			VoiceStop=0;
			if(UparmWWFlag) SoundCommand(0xf9);
			else SoundCommand(0xF8);
			if(!VoiceStop) SoundCommand(0xD4);
		}
		else if(VoiceType==13&&VoiceLevel>0)
		{
			SoundThree();
			SoundCommand2(0xD1);
		}
	}
	if(VoiceEnable==1)
	{
		SoundOff();
	}
	if(AutoKeyCount[0]==3&&AutoKeyCount[1]==1)
	{
		AutoKeyCount[0]=0;
		AutoKeyCount[1]=0;
		AutoTestFlag=1;
	}
	while(!KEY_POWER||!KEY_TIME||!KEY_MEMORYDOWN||!KEY_MEMORYUP);
	keydelay();
	while(!KEY_POWER||!KEY_TIME||!KEY_MEMORYDOWN||!KEY_MEMORYUP);
 	AllTotalTime=0;		//20130124
	if(!InfDefFlag) SetPressureVw=160;
	else SetPressureVw=280;
	AutoOffTimew=0x0000;
	IsAlgorithm=0;
	IsAlgoEnd =0;
	FirstPulse=0;
	algorithminit();
	IsPump=1;
	BPTestFlag=1;
	LBTCount=0;

	BB=VALVE | PUMP;
	iocontrolon();
	delay(4);
	do
	{
			if(!NoTimer)
				{
					showtime();
					showdate();
					flashtimepoint();
					//if(ConnectFlag&&BTIconEnable) BTIconOn;
				}
			do{}while(SamplePressure || SampleSignal);

//*********************************
		if(IsPump)
		{
			if(InfDefFlag&&UparmWWFlag)
			{
				UparmScaleValue=TestValue;
				UparmBaseValue=UparmScaleValue*60;
				firfilter2();
			}
			else firfilter();
			CalScaleFirstFlag=1;
		}
		else
		{
			if(CalScaleFirstFlag==1)
				{
					CalScaleFirstFlag=0;
					CalScale();
				}
			firfilter2();
		}
		if(((PressuremmHgw>(SetPressureVw-10))&&(!IsPump))||((IsPump)&&(PressuremmHgw<30)))
		{OscilloSignalw=245;}
//*********************************

		if(UartType==1||UartType==4||UartType==5||UartType==6) SendPressure();
		if(UartType==2)	Send_filter_test();

		if(MoveDetect)
		{
			if(MoveFlag) MoveIconOn;
		}
        if(CuffDetect)
        {
            if (CuffLoose||CuffTight)
            {
                CuffIconOn;
            }
            else if(CuffOKFlag==1) 		//20221026 add
            {
                CuffIconOn;
                OKIconOn;
            }
            if (AutoOffTimew > AutoOffTimew_1_S_COUNT * 20) //超过20秒 pumptime检测17s 则直接显示圆圈 \ps小几率出现 测试过程中有出现过臂带松紧图标不显示的情况
            {
                CuffIconOn;
            }

            // if(CuffFlag) CuffIconOn;
            // if(CuffOKFlag==1) 		//20221026 add
            // {
            // 	OKIconOn;
            // }
        }

		//DisplayToSYSDIA(InflateValueSet,1);
		calpressure();
		if(AllTotalTime>150)
		{
			IsAlgoEnd=1;
			IsAlgorithm = 0;
			IsAlgoEnd = 1;						//set algorithm end flag = 1
			ResultCode = 3;						//set result code = 3
		}

		if(!InfDefFlag)
		{
			if (!IsCalibrate)
			{
				if(IsPump)
					{
						if(!RePump) fuzzydetect();
						checkpumptime();
						In_Deflate();
						PumpPwm();
						first1flag=0;
	//					DisplayToSYSDIA(InflateValue,1);
	//					DisplayToPUL(PUMPPWMValue);
					}
				else
				{
					if(!RePump) PUMPPWM_DIS;
					In_Deflate();
					ValvePwm();
	//				DisplayToSYSDIA(DeflateValue,1);
	//				DisplayToPUL(VALVEPWMValue);
				}
				checkpressure();	//check the pressure high or low
			}
			else  deflate();
		}
		else
		{
			checkpressure();													//inflate 20180108
			checkpumptime();
			In_Deflate();
			PumpPwm();
		}

		if ((IsShowPressure&&FirstPulse==0)||(ShowPressCount>120))
		{
			showpressure();
		}

		do{}while(!SamplePressure || !SampleSignal);

		if(!InfDefFlag)
		{
			if (IsAlgorithm == 1)
			{
				AutoOffTimew=0x0000;
				algorithm();
				if (IsAlgoEnd==0)	deflate();
			}
		}
		else
		{
			algorithm();
		}

		//DisplayToSYSDIA(TruePulseCount,1);
		//DisplayToPUL(NOMORE1);
		if (IsAlgoEnd == 1)
		{
				if(ResultCode == 0)
				{
					//Send_PulseInterval();
					if(AUSMode)
					{
						do{
							ADOKFlag=0;
							while(!ADOKFlag);
							calpressure();
							showpressure();
							if(PressuremmHgw>MAX_PRESSURE) {ResultCode=3;goto ERR;}
						}while(PressuremmHgw>10&&KEY_POWER);
						while(!KEY_POWER);
						keydelay();
					}
					if(UartType==2) Send_PulseRam();
					PADDetect();
					showresults();
					resultdata();//存储结果
					if(KeyNumber==11&&SetKeyFlag) goto DELMEM;
					if(MemoryKeyFlag) goto MEM;
				}
				else
				{
					if(ResultCode == 4)
					{
							SetPressureVw+=RepumpOffset;
							if(SetPressureVw > 280) SetPressureVw = 280;
							RePump = 1;
							IsPump = 1;
							IsAlgoEnd = 0;
							IsAlgorithm = 0;
							FirstPulse=0;
							BUZZER_DIS;
							AutoOffTimew=0x0000;
							BB=POWER | VALVE | PUMP;
							iocontrolon();
					}
					else
					{
ERR:
							showerror();
							if(MemoryKeyFlag) goto MEM;
							if(KeyNumber==11&&SetKeyFlag) goto DELMEM;
					}
				}
		}
		if (IsCalibrate==0)
		{
			if (KEY_POWER==0) IsPowerOn=0;
		}
	}while(IsPowerOn);

	if(KEY_POWER)
	{
		if(SendMemoryFlag)
		{
			SendAllMemoryData();
			IsPowerOn=0;
			goto STARTUP;
		}
		if(BTFlag||AutoTestFlag)
		{
			IsPowerOn=1;
			InitialLoop();
			goto StartTest;
		}
		if(MemoryKeyFlag) goto MEM;
		if(KeyNumber==11&&SetKeyFlag) goto DELMEM;
	}
	IsPowerOn=0;
	goto STARTUP;
#endif
}

//========================================================================================

void zerotracing(void)
{
	#if 1
	unsigned char N;
	IsPowerOn=1;
	AutoOffTimew=0x0000;
	UserABDisplay();
	ShowVoice();
	if(mmHgkPaFlag==1)
		{
			if(UnitSetEnable||UnitIcon) {if(!LCD80Y) mmHgIconOn;}							//mmHg
		}
	else
		{
			if(!LCD80Y) kPaIconOn;
			kPaPointDIAIconOn;
		}
	ZeroCountw = SensorCountw;		//initial sensor count;
	N=0;
  	do
  	{
 		DisplayHalfByte(0x10,DIATen);
 		DisplayHalfByte(0x10,DIASingle);
 		kPaPointDIAIconOff;//去掉.
		delay(10);
		Mathhw=SensorCountw;
		if (Mathhw>ZeroCountw)
	     	{
	     		Mathlw=Mathhw-ZeroCountw;
	     	}
		else
	     	{
	      		Mathlw=ZeroCountw-Mathhw;
	     	}

		if ((Mathlw>8)||(RCSensorType&&(ZeroCountw<63535)&&(ZeroCountw>2000))||((ZeroCountw<0x100)&&!RCSensorType))	//R type sensor  2000<count<63535; C type senosr  count<0x100;
			{
				N=0;
 				ZeroCountw = Mathhw;
			}
		DisplayToSYSDIA(0,2);
		if(mmHgkPaFlag==1)
			{
				if(UnitSetEnable||UnitIcon) {if(!LCD80Y) mmHgIconOn;}								//mmHg
			}
		else
			{
				if(!LCD80Y) kPaIconOn;
				kPaPointDIAIconOn;
			}
		delay(10);
		N++;
	}while(N<5 && IsPowerOn && KEY_POWER);

	if (KEY_POWER==0)
		{
			if (IsCalibrate)
				{
					IsPowerOn=1;

				}
			else
				{
					IsPowerOn=0;

				}

		}

	if (IsPowerOn)
	{

		BUZZER_EN; 		/* buzzer 3/8 second beep 3/16 second and beep beep */
		AutoOffTimew=0;
		while(AutoOffTimew<25)
		{
			if(!KEY_POWER)
			{
				AutoKeyCount[1]++;
				while(!KEY_POWER)
				{

					if(AutoOffTimew>=25) break;
				}
				delay(8);
			}
		}
		BUZZER_DIS;
		delay(16);

	}
#endif
}


/************************************/
//calculation pressure
/***********************************/
void calpressure(void)
{

	unsigned int TempSpan;
	if(RCSensorType) goto RsensorCalpressure;
//**********************************************************C type sensor cal pressure;
	if((ZeroCountw>SensorCountw)&&(SensorCountw>0x100))
		{
			PressureCountw =ZeroCountw-SensorCountw ;
		}
	else
		{
			PressureCountw=0;
		}
 	TempSpan=AA1;
	if (PressureCountw < TempSpan)
		{
			TemplateValueLong=PressureCountw;
			TemplateValueLong*=1000;
			TemplateValueLong/=TempSpan;
			PressuremmHgw = TemplateValueLong;
			goto CalPend;
		}
	PressureCountw -= TempSpan;
	TempSpan=B1;
	if (PressureCountw < TempSpan)
		{
			TemplateValueLong=PressureCountw;
			TemplateValueLong*=1000;
			TemplateValueLong/=TempSpan;
			PressuremmHgw = TemplateValueLong+1000;
			goto CalPend;
		}
	PressureCountw -= TempSpan;
 	TempSpan=C1;
	TemplateValueLong=PressureCountw;
	TemplateValueLong*=1000;
	TemplateValueLong/=TempSpan;
	PressuremmHgw = TemplateValueLong+2000;
	TempSpan=25;			//各50点减去2.5mmHg;
	goto CalPend;
//**********************************************************R type sensor cal pressure;
RsensorCalpressure:
	PressureCountw =SensorCountw-ZeroCountw;
	if(PressureCountw>30000) PressureCountw=0;
	if (PressureCountw <= AA1)
		{
			TemplateValueLong=PressureCountw;
			TemplateValueLong = TemplateValueLong*10*300;
			TemplateValueLong = TemplateValueLong/AA1;
			PressuremmHgw=TemplateValueLong;
		}
	else
		{
			TemplateValueLong=PressureCountw-AA1;
			TemplateValueLong = TemplateValueLong*10*300;
			TemplateValueLong = TemplateValueLong/AA1;
			PressuremmHgw=TemplateValueLong+3000;
		}
	TempSpan=0;					//各50点减去0mmHg;

CalPend:
//*********************************新增50点需减去
/*	TempSpan=25;			//各50点减去2.5mmHg;
	Xx.w=PressuremmHgw;
	Xx.w%=1000;
	if(Xx.w>500)
		{TempTempresure=(1000-Xx.w)*TempSpan/500;}
	else{TempTempresure=Xx.w*TempSpan/500;}
	PressuremmHgw-=TempTempresure;*/
//*********************************新增50点需减去
	PressureBackup=PressuremmHgw;
	if (!IsCalibrate)
		{
			PressuremmHgw/=10;		//正常mode下,压力精确到个位.校压mode下精确到0.1.
		}

	if (IsCalibrate)  SysMeanEnd = PressuremmHgw;

}




void tomemorykeyin(void)
{
#if 1
//	unsigned int 	TempSYS;
//	unsigned int	TempDIA;
	unsigned char	i;
//	static int	time_change_flag = 0;

	uint8 MemoryDisplay=1;
	MemoryMode=1;
	MemoryChangeFlag=0;
	HaveMemoryAvg=0;
	HaveMemoryAvg1=0;
	HaveMemoryFirst=1;
	MemoryClredFlag=0;

	checkmemorybankAB();
	MemoryMode=1;
	EEPROMin = 0;
	readM24L16();
	//FLASH_Read(UserStartAddress,MemBack,2048);//JACK  TEST 20210603
//**********************************************20110503修改最后的平均值组数可以自定义.
	MemoryEndIndex = inbyte[0];		//reload first address	//用于找最后一笔记忆值的index
	MemoryEndIndex<<=8;
	MemoryEndIndex+=inbyte[1];
	MemoryEndIndex--;

	if(MemoryFull)	{MemoryIndex = MemorySet;}	//load memory count //用于循环计数 如果full,则全部.
	else			{MemoryIndex = MemoryEndIndex;}	//如果没有full,则最后一笔就是全部笔数.

	MemoryIndexBackup=MemoryIndex;
	MemoryEndIndexBackup=MemoryEndIndex;

	if((MemoryEndIndex==0 && MemoryFull==0)||(ReadEepromError==1)||(MemoryEndIndex>MemorySet)) // No memory display "No M"
	{
		DarkAllIcon();
		AutoOffTimew=0;
		DisplayHalfByte(0x16,MemorySetTen); //n
		DisplayHalfByte(0x14,MemorySetSingle);//o
		MemoryIconOn;//MarkMEMORY = 1;			//MR icon display
		UserABDisplay();
		ShowVoice();
		do{}while(!KEY_MEMORYDOWN||!KEY_MEMORYUP||!KEY_USER||!KEY_TIME);
		keydelay();
		KeyModeFlag.b=0;
		do{
			delay(1);

			if(KeyNumber!=7)
			{
				if(KeyNumber==11||KeyNumber==12)
				{
					if(LongSetFlag) {SetKeyFlag=1;break;}
				}
				else if(!KEY_TIME||!KEY_MEMORYUP||!KEY_MEMORYDOWN) break;
			}

			if(!AllTimeFlag)
			{
				if(ModifyFlag)
				{
					if(AutoOffTimew>AUTOOFFTIME) break;
				}
				else
				{
					if(AutoOffTimew>400) break;
				}
			}

		}while(KEY_POWER);
		keydelay();
		goto TimeOver;
	}

	SysMeanEnd=DiaMeanEnd=PulseMeanEnd=0;
	if(MemoryFull==0)
		{if(AverageSet>MemoryEndIndex)
			{AverageSet=MemoryEndIndex;}
		}
	if(((MemoryEndIndex>0)||(MemoryFull==1))&&ShowMean)		//如果有记忆值大于1,且有显示平均值功能,
		{
			DarkAllIcon();
			DisplayHalfByte(0x0a,MemorySetTen);  //显示AV
			DisplayHalfByte(0x18,MemorySetSingle);
			MemoryIconOn;

			for(i=0;i<AverageSet;i++)
				{
					EEPROMin = MemoryEndIndex;
					readM24L16();
					SysMeanEnd += inbyte[0];
					DiaMeanEnd += inbyte[1];
					PulseMeanEnd += inbyte[2];

					MemoryEndIndex--;
					if(MemoryEndIndex==0){MemoryEndIndex = MemorySet;}
				}

			SysMeanEnd /=AverageSet;
			DiaMeanEnd /= AverageSet;
			PulseMeanEnd /= AverageSet;
		}

//	tomemoryMemorySenevAVg(MemoryEndIndex);

//	while(KEY_TIME && KEY_POWER)		//如果power or time key有按下,则中止记忆显示
	while(1)					//20111211如果power则中止记忆显示
	{
		if(HaveMemoryAvg==0)
		{
			HaveMemoryAvg1=1;

			EEPROMin = 0;
			readM24L16();

			MemoryEndIndex = inbyte[0];		//reload first address	//用于找最后一笔记忆值的index
			MemoryEndIndex<<=8;
			MemoryEndIndex+=inbyte[1];
			MemoryEndIndex--;

			if(MemoryFull) 	MemoryIndex = MemorySet;	//load memory count //用于循环计数 如果full,则全部.
			else		MemoryIndex = MemoryEndIndex;	//如果没有full,则最后一笔就是全部笔数.

			MemoryIndexBackup=MemoryIndex;
			MemoryEndIndexBackup=MemoryEndIndex;

			if(MemoryEndIndex >=1)
			{
				HaveMemoryAvg = 1;
				MemoryClredFlag=0;
				if(!ShowMean) HaveMemoryFirst=0;
				if(HaveMemoryFirst==0) goto NoAverage;	//no display average
			}

            if((unsigned char)PulseMeanEnd<MIN_PULSERATE)
            {
                DisplayHalfByte(0x13,PulseTen);/*L*/
                DisplayHalfByte(0x14,PulseSingle);/*o*/
                PulseMeanEnd = 0;
            }
            else if((unsigned char)PulseMeanEnd>MAX_PULSERATE)
            {
                DisplayHalfByte(0x11,PulseTen);/*H*/
                DisplayHalfByte(0x12,PulseSingle);/*I*/
                PulseMeanEnd = 0;
            }
            else
            {
                DisplayToPUL((unsigned char)PulseMeanEnd);
            }

			// DisplayToPUL((unsigned char)PulseMeanEnd);
			mmHgKpaDisplay((unsigned char)SysMeanEnd,(unsigned char)DiaMeanEnd);
			MemoryIconOn;					//MR icon display
			UserABDisplay();
			ShowVoice();

			MemoryEndIndex = MemoryEndIndex+1;		//
			MemoryIndex = MemoryIndex+1;			//20220817

			if(!BLFlag) DPDetect(SysMeanEnd,DiaMeanEnd);
			if(BPLevelType!=0){ShowWHO(SysMeanEnd,DiaMeanEnd);}//20120317

			AutoOffTimew=0;

			while(!KEY_MEMORYDOWN||!KEY_MEMORYUP||!KEY_TIME||!KEY_USER);
			keydelay();


//*****************************************语音部分
			if(VoiceEnable==1)
			{
				if(KeyNumber==7)
				{
					AutoOffTimew=0;
					while(KEY_POWER&&KEY_MEMORYDOWN&&KEY_MEMORYUP&&KEY_USER&&(AutoOffTimew<50));
					if(!KEY_POWER||!KEY_MEMORYDOWN||!KEY_MEMORYUP||!KEY_USER) goto ChangeMemoryIndex;
				}
				VoiceStop=0;
				if(VoiceType==1||VoiceType==14)
				{
					if((VoiceType==1) && (VoiceType2==2)) 		//20230508 CN+MD
					{
						SoundCommand(0xD3);	//平均血压
						if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
						if(mmHgkPaFlag){SoundAllCommand(0x55,SysMeanEnd,DiaMeanEnd,PulseMeanEnd);}//平均血压+高压是+SYS+毫米汞柱+低压是+DIA+毫米汞柱+每分钟心跳次数是+PUL+次
						else
						{
							if(VoiceFlag==0)
							{
								SoundAllCommand(0xaa,SysMeanEnd,DiaMeanEnd,PulseMeanEnd);
							}

						}		//kpa

						if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
						if(BPLevelType==1||BPLevelType==3)
						{
							SoundAllCommand(0x66,WHOLevel,0,0);//根据世界卫生组织标准,您的血压正常/正常值偏高/轻度高血压/中度高血压/重度高血压
							if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
						}
					}
                    else if(VoiceType==1&&VoiceType2==3)
                    {
                        if(mmHgkPaFlag==0)
                        {

                        }
                        else
                        {
                            volume_adjus_china_eng_malay(VoiceLevel);//中语英语马来西亚语音量调节
                            SoundCommand(0xD2);	//D2H 平均血压
                            if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}
                            if(mmHgkPaFlag) SoundAllCommand(0x55,SysMeanEnd,DiaMeanEnd,PulseMeanEnd);//平均血压+高压是+SYS+毫米汞柱+低压是+DIA+毫米汞柱+每分钟心跳次数是+PUL+次
                            if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
                            if(BPLevelType==1){
                                delay(60);//新需求 who前加延时 0.8s
                                SoundAllCommand(0x66,WHOLevel,0,0);//根据世界卫生组织标准,您的血压正常/正常值偏高/轻度高血压/中度高血压/重度高血压
                                if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}
                                if(WHOLevel>=4){SoundCommand(0xD7);}	//D7H 若连续几天都维持这数值请恰询您的医师
                                if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}
                            }
                        }
                    }
					else
					{
						SoundCommand(0xD8);	//平均血压
						if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
						if(mmHgkPaFlag){SoundAllCommand(0x55,SysMeanEnd,DiaMeanEnd,PulseMeanEnd);}//平均血压+高压是+SYS+毫米汞柱+低压是+DIA+毫米汞柱+每分钟心跳次数是+PUL+次
						else{SoundAllCommand(0xaa,SysMeanEnd,DiaMeanEnd,PulseMeanEnd);}		//kpa
						if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
						if(BPLevelType==1||BPLevelType==3)
						{
							SoundAllCommand(0x66,WHOLevel,0,0);//根据世界卫生组织标准,您的血压正常/正常值偏高/轻度高血压/中度高血压/重度高血压
							if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
							if(WHOLevel>=4){SoundCommand(0xe5);}	//若连续几天都维持这数值,请恰询您的医师
							if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
						}
					}
				}
				else if(VoiceType>=2&&VoiceType<=4)
				{
					VoiceStop=0;
					SoundCommand(0x93);	//平均血压
					if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
					if(AverageType) SoundCommand(0x94);	//平均血压3组  0x95全部
					else SoundCommand(0x95);
					if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
					SoundAllCommand(0x11,SysMeanEnd,DiaMeanEnd,PulseMeanEnd);//平均血压+高压是+SYS+毫米汞柱+低压是+DIA+毫米汞柱+每分钟心跳次数是+PUL+次
					if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
					if((BPLevelType==1) || (BPLevelType==8))
					{
						if((BPLevelType==8) && FreWho130Flag)	{VoiceStop=0;goto VoiceOver;}
						SoundAllCommand(0x22,WHOLevel,0,0);//根据世界卫生组织标准,您的血压正常/正常值偏高/轻度高血压/中度高血压/重度高血压
						if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
					}
				}
				else if(VoiceType==5)
				{
					SoundCommand(0xc3);	//Your average for
					if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}
					if(AverageType) SoundCommand(0xc4);
					else SoundCommand(0xc5);
					if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}
					SoundAllCommand(0x55,SysMeanEnd,DiaMeanEnd,PulseMeanEnd);//平均血压+高压是+SYS+毫米汞柱+低压是+DIA+毫米汞柱+每分钟心跳次数是+PUL+次
					if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
					if(BPLevelType==1){
						SoundAllCommand(0x66,WHOLevel,0,0);//根据世界卫生组织标准,您的血压正常/正常值偏高/轻度高血压/中度高血压/重度高血压
						if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
					}
				}
				else if(VoiceType==7)
				{
					SoundCommand(0xEB);
					if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}
					SoundAllCommand(0x77,SysMeanEnd,DiaMeanEnd,PulseMeanEnd);
					if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}
				}
				else if (VoiceType==6)
				{
					if(VoiceFlag==1&&!mmHgkPaFlag) {VoiceStop=0;goto VoiceOver;}
					SoundCommand2(0xD8);	//平均血压
					if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}
					if(mmHgkPaFlag){SoundAllCommand2(0x55,SysMeanEnd,DiaMeanEnd,PulseMeanEnd);}//平均血压+高压是+SYS+毫米汞柱+低压是+DIA+毫米汞柱+每分钟心跳次数是+PUL+次
					else{SoundAllCommand2(0xaa,SysMeanEnd,DiaMeanEnd,PulseMeanEnd);}		//kpa
					if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
					if(BPLevelType==1){
						SoundAllCommand2(0x66,WHOLevel,0,0);//根据世界卫生组织标准,您的血压正常/正常值偏高/轻度高血压/中度高血压/重度高血压
						if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
						if(WHOLevel>=4){SoundCommand2(0xe5);}	//若连续几天都维持这数值,请恰询您的医师
						if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
					}
				}
				else if(VoiceType==8&&VoiceFlag<5)
				{
					SoundFive();
					SoundCommand2(0xD3);	//Your average for
					if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}
					if(AverageType) SoundCommand2(0xd4);	//=1三组
					else SoundCommand2(0xd5);
					if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}
					SoundAllCommand2(0x55,SysMeanEnd,DiaMeanEnd,PulseMeanEnd);//平均血压+高压是+SYS+毫米汞柱+低压是+DIA+毫米汞柱+每分钟心跳次数是+PUL+次
					if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
					if(BPLevelType==1){
						SoundAllCommand2(0x66,WHOLevel,0,0);//根据世界卫生组织标准,您的血压正常/正常值偏高/轻度高血压/中度高血压/重度高血压
						if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
					}
				}
				else if(VoiceType==9)
				{
					SoundCommand(0xc4);
					if(VoiceStop) {VoiceStop=0;goto ChangeMemoryIndex;}
					if(mmHgkPaFlag){SoundAllCommand(0x55,SysMeanEnd,DiaMeanEnd,PulseMeanEnd);}//  i =?
					if(VoiceStop) {VoiceStop=0;goto ChangeMemoryIndex;}
					if(BPLevelType==1){
						SoundAllCommand(0x66,WHOLevel,0,0);
						if(VoiceStop) {VoiceStop=0;goto ChangeMemoryIndex;}
						if(WHOLevel==4||WHOLevel==3){SoundCommand(0xCE);}
						if(VoiceStop) {VoiceStop=0;goto ChangeMemoryIndex;}
					}
				}
				else if(VoiceType==10)	//Khmer
				{
					SoundCommand(0xB6);	//Average Blood Pressure
					if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}
					SoundAllCommand(0x22,SysMeanEnd,DiaMeanEnd,PulseMeanEnd);	//your blood pressure was SYS + DIA + PUL
					if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}
				}
				else if(VoiceType==11)
				{
					VoiceStop=0;
					SoundCommand2(0xD4);	//平均血压
					if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
					if(AverageType) SoundCommand2(0xd5);	//平均血压3组  0x95全部
					else SoundCommand2(0xd6);
					if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
					SoundAllCommand2(0x44,SysMeanEnd,DiaMeanEnd,PulseMeanEnd);//平均血压+高压是+SYS+毫米汞柱+低压是+DIA+毫米汞柱+每分钟心跳次数是+PUL+次
					if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
					if(BPLevelType==1){
						if(WHOLevel<6) SoundAllCommand2(0x55,WHOLevel,0,0);//根据世界卫生组织标准,您的血压正常/正常值偏高/轻度高血压/中度高血压/重度高血压
						else
						{
							SoundCommand2(0xc6);
							if(VoiceStop) {VoiceStop=0;goto ChangeMemoryIndex;}
							SoundCommand2(0xc7);
							if(VoiceStop) {VoiceStop=0;goto ChangeMemoryIndex;}
							SoundCommand2(0xce);
						}
						if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
					}
				}
				else if(VoiceType==12)
				{
					if(AverageType) SoundAllCommand(0xC8,0,0,0);//3组平均
					else SoundCommand(0xD8);//全部平均
					if(VoiceStop) {VoiceStop=0;goto ChangeMemoryIndex;}
					if(mmHgkPaFlag) SoundAllCommand(0x55,SysMeanEnd,DiaMeanEnd,PulseMeanEnd);
					else SoundAllCommand(0xAA,SysMeanEnd,DiaMeanEnd,PulseMeanEnd);
					if(VoiceStop) {VoiceStop=0;goto ChangeMemoryIndex;}
					SoundWHO(SysMeanEnd,DiaMeanEnd);
					if(VoiceStop) {VoiceStop=0;goto ChangeMemoryIndex;}
				}
				else if(VoiceType==13&&VoiceLevel>0)
				{
					if(VoiceType>0&&mmHgkPaFlag==0)
					{

					}
					else
					{
						SoundThree();
						SoundCommand2(0xD5);	//Your average for
						if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}
						SoundThree();
						if(mmHgkPaFlag) SoundAllCommand2(0x55,SysMeanEnd,DiaMeanEnd,PulseMeanEnd);//平均血压+高压是+SYS+毫米汞柱+低压是+DIA+毫米汞柱+每分钟心跳次数是+PUL+次
						else SoundAllCommand2(0xAA,SysMeanEnd,DiaMeanEnd,PulseMeanEnd);
						if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
						if(BPLevelType==1){
							SoundThree();
							SoundAllCommand2(0x66,WHOLevel,0,0);//根据世界卫生组织标准,您的血压正常/正常值偏高/轻度高血压/中度高血压/重度高血压
							if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}
							SoundThree();
							if(WHOLevel==5&&(VoiceType==0)){SoundCommand(0xE2);}
							if(WHOLevel==3&&(VoiceType>0)){SoundCommand(0xE2);}
							if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}
						}
					}
				}

			}

		}
//*****************************************语音部分
		else
		{
NoAverage:	HaveMemoryAvg1=0;
			DarkAllIcon();

//			UserABDisplay();
//			DisplayToPUL(MemoryIndex);
//			MemoryIconOn;
			tomemorykeyinX(MemoryEndIndex);

            if (PulseRam[3].b[0] > MAX_PULSERATE)
            {
                DisplayHalfByte(0x11,PulseTen);          /* 'H' */
                DisplayHalfByte(0x12,PulseSingle);          /* 'I' */
            }
            else if(PulseRam[3].b[0] < MIN_PULSERATE)
            {
                DisplayHalfByte(0x13,PulseTen);          /* 'L' */
                DisplayHalfByte(0x14,PulseSingle);          /* 'O' */
            }
            else 	DisplayToPUL(PulseRam[3].b[0]);

            mmHgKpaDisplay(PulseRam[1].b[0],PulseRam[2].b[0]);

			if(VoiceType==12)
			{
				MemoryDisplay=MemoryIndexBackup-MemoryIndex+1;//JACK   MemoryIndexBackup 初始化 ？
				DisplayToMemorySet(MemoryDisplay);
			}
			else
			{
				DisplayToMemorySet(MemoryIndex);
			}
			UserABDisplay();
			ShowVoice();
			if(!HaveMemoryAvg1 && !NoTimer)
				{ShowMemoryDate(PulseRam[4].b[0],PulseRam[5].b[0]);ShowMemoryTime(PulseRam[6].b[0],PulseRam[7].b[0]);}	//HH:MM

			if(!BLFlag) DPDetect(PulseRam[1].b[0],PulseRam[2].b[0]);
			if(BPLevelType!=0)
			{ShowWHO(PulseRam[1].b[0],PulseRam[2].b[0]);}	//20101226新增WHO显示
			if(PADEnable==1)
				{
					if(PADFlag==1)
					{PADIconOn;}
				}
            if (CuffDetect)
            {
                CuffIconOn;
                if(CuffOKFlag==1) 		//20221026 add
                {
                    OKIconOn;
                }
            }
            if (MoveDetect)
            {
                if(MoveFlag == 1)//MoveFlag
                    MoveIconOn;
            }
			while(!KEY_MEMORYUP||!KEY_MEMORYDOWN||!KEY_TIME||!KEY_POWER);
			delay(8);

//*************************语音部分
			if(VoiceEnable==1)
			{
				if(KeyNumber==7)
				{
					AutoOffTimew=0;
					while(KEY_POWER&&KEY_MEMORYDOWN&&KEY_MEMORYUP&&KEY_USER&&(AutoOffTimew<50));
					if(!KEY_POWER||!KEY_MEMORYDOWN||!KEY_MEMORYUP||!KEY_USER) goto ChangeMemoryIndex;
				}
				VoiceStop=0;
				if((PulseRam[3].b[0]>=MIN_PULSERATE)&&(PulseRam[3].b[0]<=MAX_PULSERATE)){i=PulseRam[3].b[0];}
				else{i=0;}
				if(VoiceType==1||VoiceType==14)
				{
					if((VoiceType==1) && (VoiceType2==2)) 		//20230508 CN+MD
					{
						if(mmHgkPaFlag){SoundAllCommand(0x55,PulseRam[1].b[0],PulseRam[2].b[0],i);}	//高压是+SYS+毫米汞柱+低压是+DIA+毫米汞柱+每分钟心跳次数是+PUL+次
						else
						{
							if(VoiceFlag==0)
							{
								SoundAllCommand(0xaa,PulseRam[1].b[0],PulseRam[2].b[0],i);
							}

						}	//kpa;
						if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
						if(BPLevelType==1||BPLevelType==3)
						{
							SoundAllCommand(0x66,WHOLevel,0,0);//根据世界卫生组织标准,您的血压正常/正常值偏高/轻度高血压/中度高血压/重度高血压
							if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
						}
//						if((PADEnable==1)&&(PADFlag==1))
//							{SoundCommand(0xE7);}		//请注意,此次量测有侦测到心率不齐,请按指示重新量测.如连续三次均测出心率不齐,请恰询您的医师
//						if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
					}
                    else if(VoiceType==1&&VoiceType2==3)
                    {
                        if(mmHgkPaFlag==0)
                        {

                        }
                        else
                        {
                            volume_adjus_china_eng_malay(VoiceLevel);//中语英语马来西亚语音量调节
                            if(mmHgkPaFlag) SoundAllCommand(0x55,PulseRam[1].b[0],PulseRam[2].b[0],i);//高压是+SYS+毫米汞柱+低压是+DIA+毫米汞柱+每分钟心跳次数是+PUL+次
                            if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
                            if(BPLevelType==1){
                                delay(60);//新需求 who前加延时 0.8s
                                SoundAllCommand(0x66,WHOLevel,0,0);//根据世界卫生组织标准,您的血压正常/正常值偏高/轻度高血压/中度高血压/重度高血压
                                if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}
                                if(WHOLevel>=4){SoundCommand(0xD7);}	//D7H 若连续几天都维持这数值请恰询您的医师
                                if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
                            }
                            if((PADEnable==1)&&(PADFlag==1))
                                {SoundCommand(0xD9);}		//D9H请注意,此次量测有侦测到心率不齐，请按指示重新量测.如连续三次均测出心率不齐，请恰询您的医师
                            if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}
                        }
                    }
					else
					{
						if(mmHgkPaFlag){SoundAllCommand(0x55,PulseRam[1].b[0],PulseRam[2].b[0],i);}	//高压是+SYS+毫米汞柱+低压是+DIA+毫米汞柱+每分钟心跳次数是+PUL+次
						else{SoundAllCommand(0xaa,PulseRam[1].b[0],PulseRam[2].b[0],i);}	//kpa;
						if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
						if(BPLevelType==1||BPLevelType==3)
						{
							SoundAllCommand(0x66,WHOLevel,0,0);//根据世界卫生组织标准,您的血压正常/正常值偏高/轻度高血压/中度高血压/重度高血压
							if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
							if(WHOLevel>=4){SoundCommand(0xe5);}	//若连续几天都维持这数值,请恰询您的医师
							if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
						}
						if((PADEnable==1)&&(PADFlag==1))
							{SoundCommand(0xE7);}		//请注意,此次量测有侦测到心率不齐,请按指示重新量测.如连续三次均测出心率不齐,请恰询您的医师
						if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
					}
				}
				else if(VoiceType>=2&&VoiceType<=4)
				{
					SoundAllCommand(0x11,PulseRam[1].b[0],PulseRam[2].b[0],i);	//高压是+SYS+毫米汞柱+低压是+DIA+毫米汞柱+每分钟心跳次数是+PUL+次
					if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
					if((BPLevelType==1) || (BPLevelType==8))
					{
						if((BPLevelType==8) && FreWho130Flag)	{VoiceStop=0;goto VoiceOver;}
						SoundAllCommand(0x22,WHOLevel,0,0);//根据世界卫生组织标准,您的血压正常/正常值偏高/轻度高血压/中度高血压/重度高血压
						if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
					}
				}
				else if(VoiceType==5)
				{
					SoundAllCommand(0x55,PulseRam[1].b[0],PulseRam[2].b[0],i);	//高压是+SYS+毫米汞柱+低压是+DIA+毫米汞柱+每分钟心跳次数是+PUL+次
					if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
					if(BPLevelType==1){
						SoundAllCommand(0x66,WHOLevel,0,0);//根据世界卫生组织标准,您的血压正常/正常值偏高/轻度高血压/中度高血压/重度高血压
						if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
					}
				}
				else if(VoiceType==7)
				{
					SoundAllCommand(0x77,PulseRam[1].b[0],PulseRam[2].b[0],i);
					if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
				}
				else if(VoiceType==6)
				{
					if(VoiceFlag==1&&!mmHgkPaFlag) {VoiceStop=0;goto VoiceOver;}
					if(mmHgkPaFlag){SoundAllCommand2(0x55,PulseRam[1].b[0],PulseRam[2].b[0],i);}	//高压是+SYS+毫米汞柱+低压是+DIA+毫米汞柱+每分钟心跳次数是+PUL+次
					else{SoundAllCommand2(0xaa,PulseRam[1].b[0],PulseRam[2].b[0],i);}	//kpa;
					if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
					if(BPLevelType==1){
						SoundAllCommand2(0x66,WHOLevel,0,0);//根据世界卫生组织标准,您的血压正常/正常值偏高/轻度高血压/中度高血压/重度高血压
						if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
						if(WHOLevel>=4){SoundCommand2(0xe5);}	//若连续几天都维持这数值,请恰询您的医师
						if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
					}
					if((PADEnable==1)&&(PADFlag==1))
						{SoundCommand2(0xE7);}		//请注意,此次量测有侦测到心率不齐,请按指示重新量测.如连续三次均测出心率不齐,请恰询您的医师
					if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
				}
				else if(VoiceType==8&&VoiceFlag<5)
				{
					SoundFive();
					SoundAllCommand2(0x55,PulseRam[1].b[0],PulseRam[2].b[0],i);	//高压是+SYS+毫米汞柱+低压是+DIA+毫米汞柱+每分钟心跳次数是+PUL+次
					if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
					if(BPLevelType==1){
						SoundAllCommand2(0x66,WHOLevel,0,0);//根据世界卫生组织标准,您的血压正常/正常值偏高/轻度高血压/中度高血压/重度高血压
						if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
					}
				}
				else if(VoiceType==9)
				{
					if(mmHgkPaFlag){SoundAllCommand(0x55,PulseRam[1].b[0],PulseRam[2].b[0],i);}
					if(VoiceStop) {VoiceStop=0;goto ChangeMemoryIndex;}
					if(BPLevelType==1){
						SoundAllCommand(0x66,WHOLevel,0,0);
						if(VoiceStop) {VoiceStop=0;goto ChangeMemoryIndex;}
						if(WHOLevel==4||WHOLevel==3){SoundCommand(0xCE);}
						if(VoiceStop) {VoiceStop=0;goto ChangeMemoryIndex;}
					}
				}
				else if(VoiceType==10)	//Khmer
				{
					SoundCommand(0x8F);	//Last time
					if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}
					SoundAllCommand(0x22,PulseRam[1].b[0],PulseRam[2].b[0],i);	//your blood pressure was SYS + DIA + PUL
					if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}
				}
				else if(VoiceType==11)
				{
					SoundAllCommand2(0x44,PulseRam[1].b[0],PulseRam[2].b[0],i);	//高压是+SYS+毫米汞柱+低压是+DIA+毫米汞柱+每分钟心跳次数是+PUL+次
					if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
					if(BPLevelType==1){
						if(WHOLevel<6) SoundAllCommand2(0x55,WHOLevel,0,0);//根据世界卫生组织标准,您的血压正常/正常值偏高/轻度高血压/中度高血压/重度高血压
						else
						{
							SoundCommand2(0xc6);
							if(VoiceStop) {VoiceStop=0;goto ChangeMemoryIndex;}
							SoundCommand2(0xc7);
							if(VoiceStop) {VoiceStop=0;goto ChangeMemoryIndex;}
							SoundCommand2(0xce);
						}
						if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
					}
				}
				else if(VoiceType==12)
				{
					SoundAllCommand(0x33,MemoryDisplay,0,0);
					if(VoiceStop) {VoiceStop=0;goto ChangeMemoryIndex;}
					if(mmHgkPaFlag) SoundAllCommand(0x55,PulseRam[1].b[0],PulseRam[2].b[0],i);
					else SoundAllCommand(0xAA,PulseRam[1].b[0],PulseRam[2].b[0],i);
					if(VoiceStop) {VoiceStop=0;goto ChangeMemoryIndex;}
					SoundWHO(PulseRam[1].b[0],PulseRam[2].b[0]);
					if(VoiceStop) {VoiceStop=0;goto ChangeMemoryIndex;}
				}
				else if(VoiceType==13&&VoiceLevel>0)
				{
					if(VoiceType>0&&mmHgkPaFlag==0)
					{

					}
					else
					{
						SoundThree();
						if(mmHgkPaFlag) SoundAllCommand2(0x55,PulseRam[1].b[0],PulseRam[2].b[0],i);//平均血压+高压是+SYS+毫米汞柱+低压是+DIA+毫米汞柱+每分钟心跳次数是+PUL+次
						else SoundAllCommand2(0xAA,PulseRam[1].b[0],PulseRam[2].b[0],i);
						if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}//goto VoiceOver;}
						if(BPLevelType==1){
							SoundThree();
							SoundAllCommand2(0x66,WHOLevel,0,0);//根据世界卫生组织标准,您的血压正常/正常值偏高/轻度高血压/中度高血压/重度高血压
							if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}
							SoundThree();
							if(WHOLevel==5&&(VoiceType==0)){SoundCommand(0xE2);}
							if(WHOLevel==3&&(VoiceType>0)){SoundCommand(0xE2);}
							if(VoiceStop==1){VoiceStop=0;goto ChangeMemoryIndex;}
						}
					}
				}
			}

//*************************语音部分
		}
VoiceOver:
		delay(1);
		KeyModeFlag.b=0;
		AutoOffTimew=0;
		mtemp0c.b=0;
		mtemp1c.b=0;
		SecondFlag = 0;
		while(KEY_POWER)
		{
			if(ModifyFlag)
			{
				if(AutoOffTimew>AUTOOFFTIME&&!AllTimeFlag)
				{
					IsPowerOn=0;
					goto TimeOver;
				}
			}
			else
			{
				if(AutoOffTimew>400&&!AllTimeFlag)
				{
					IsPowerOn=0;
					goto TimeOver;
				}
			}
			delay(1);



			if(KeyNumber==11&&LongSetFlag) {SetKeyFlag=1;goto TimeOver;}
			if(KeyNumber!=11&&!KEY_TIME&&!ThreeKeyFlag) break;
			if(!KEY_TIME || !KEY_MEMORYUP || !KEY_POWER) break;
			if(KeyNumber==7&&!KEY_USER) {MemoryChangeFlag=1;break;}
		}
ChangeMemoryIndex:
		if(VoiceEnable)	SoundOff();
		if(!KEY_POWER) goto TimeOver;
		if(ThreeKeyFlag)
			{
				if(KeyNumber!=9)
				{
//					if(HaveMemoryFirst==1 &&!KEY_MEMORYUP){goto 	NoChangeMemoryIndex;}
					if(!KEY_MEMORYUP)
					 {
						while(!KEY_MEMORYUP);
						delay(4);
						MemoryIndex--;
						if(MemoryIndex > MemorySet) MemoryIndex = 0;
						MemoryEndIndex--;
						if(MemoryEndIndex > MemorySet) MemoryEndIndex = 0;

						if(MemoryEndIndex == 0)
						{
							if(MemoryFull )	 MemoryEndIndex = MemorySet;
							else MemoryEndIndex = MemoryEndIndexBackup;

						}
						if(MemoryIndex == 0) MemoryIndex=MemoryIndexBackup;



					}

					if(!KEY_TIME)
					 {
						while(!KEY_TIME);
						delay(4);
						MemoryIndex++;
						if(MemoryIndex > MemoryIndexBackup)  MemoryIndex=1;
						MemoryEndIndex++;
						if(MemoryFull==0)
							{
								if(MemoryEndIndex >MemoryEndIndexBackup) MemoryEndIndex = 1;
							}
						else{if(MemoryEndIndex >MemorySet) MemoryEndIndex = 1;}
					}



				}
				else
				{
					if(HaveMemoryFirst==1 &&!KEY_MEMORYDOWN){goto 	NoChangeMemoryIndex;}
					if(!KEY_MEMORYDOWN)
					{
						MemoryIndex--;
						if(MemoryIndex > MemorySet) MemoryIndex = 0;
						MemoryEndIndex--;
						if(MemoryEndIndex > MemorySet) MemoryEndIndex = 0;

						if(MemoryEndIndex == 0) MemoryEndIndex = MemorySet;
						if(MemoryIndex == 0) HaveMemoryAvg=0;
					}
				}
			}
		else
			{
				if(HaveMemoryFirst==1 &&!KEY_TIME){goto 	NoChangeMemoryIndex;}
				if(!KEY_TIME)
				{
					MemoryIndex--;
					if(MemoryIndex > MemorySet) MemoryIndex = 0;
					MemoryEndIndex--;
					if(MemoryEndIndex > MemorySet) MemoryEndIndex = 0;

					if(MemoryEndIndex == 0) MemoryEndIndex = MemorySet;
					if(MemoryIndex == 0) HaveMemoryAvg=0;
				}
			}

			if(KeyNumber!=9)
			{
				if(!KEY_MEMORYDOWN)//20120416去掉时间设定可以翻页功能.
					{
						MemoryIndex++;
						if(MemoryIndex >MemoryIndexBackup) MemoryIndex=1;
						MemoryEndIndex++;
						if(MemoryFull==0)
							{
								if(MemoryEndIndex >MemoryEndIndexBackup) MemoryEndIndex = 1;
							}
						else{if(MemoryEndIndex >MemorySet) MemoryEndIndex = 1;}
					//	if(MemoryEndIndex == 0) MemoryEndIndex = MemorySet;
					//	if(MemoryIndex == 0) HaveMemoryAvg=0;
					}
				}
			else
			{
				if(!KEY_MEMORYUP)//20120416去掉时间设定可以翻页功能.
					{
						MemoryIndex++;
						if(MemoryIndex >MemoryIndexBackup) MemoryIndex=1;
						MemoryEndIndex++;
						if(MemoryFull==0)
							{
								if(MemoryEndIndex >MemoryEndIndexBackup) MemoryEndIndex = 1;
							}
						else{if(MemoryEndIndex >MemorySet) MemoryEndIndex = 1;}
					//	if(MemoryEndIndex == 0) MemoryEndIndex = MemorySet;
					//	if(MemoryIndex == 0) HaveMemoryAvg=0;
					}
			}
NoChangeMemoryIndex:
		HaveMemoryFirst=0;  //第二次查记忆时,不能清除记忆.
		AutoOffTimew=0;
		if(KeyNumber==12)
		{
			while(!KEY_TIME)
			{
				if(LongSetFlag) {SetKeyFlag=1;goto TimeOver;}
			}
		}
		if(KeyNumber==1)
		{
			while(!KEY_POWER&&(AutoOffTimew<150));
			if(AutoOffTimew>149) goto TimeOver;
		}
		//while(!KEY_MEMORYDOWN || !KEY_MEMORYUP ||!KEY_TIME);
		keydelay();
	}

TimeOver:
	HaveMemoryAvg=0;
	DarkAllIcon();
	MemoryMode=0;
	while(!KEY_POWER);
	delay(4);
#endif
}



void	checkpumptime(void)
{
	unsigned int PumpTimeInf;
	unsigned int AllPumpTime;
	if(UparmWWFlag==1){PumpTimeInf= AutoOffTimew_1_S_COUNT * 15;}		//500
	else{PumpTimeInf= AutoOffTimew_1_S_COUNT * 15;}

	if(InfDefFlag)
	{
		AllPumpTime=4200;
		PumpTimeInf=3500;
	}
	else AllPumpTime=3000;

	if (((AutoOffTimew > PumpTimeInf) && (PressuremmHgw < PUMPTIMEP)) || (AutoOffTimew > AllPumpTime ))  //30S总充气时间
	{
	   	IsAlgorithm = 0;
	   	IsAlgoEnd = 1;		/* set algorithm end flag = 1 */
	   	ResultCode = 3;		/* set result code = 3 */
	}

	if(AutoOffTimew>120&&AutoOffTimew<500&&PressuremmHgw>30)   //2-10s P>30
	{
		CuffNormal = 1;

		CuffFlag=1;

		if((CuffLoose == 0) && (CuffTight == 0))
		{
			CuffOKFlag=1;
		}
	}
 	else if(AutoOffTimew>AutoOffTimew_1_S_COUNT * 10&&AutoOffTimew<=AutoOffTimew_1_S_COUNT * 15&&(PressuremmHgw>=30 && CuffNormal == 0))		//11-15s 偏松  11-15秒内    加到30mmHg      只显示圆圈，不显示ok   查记忆时也要显示这次测量的圆圈
	{
		CuffLoose = 1;

		CuffFlag=1;
		CuffOKFlag=0;
	}
	if(AutoOffTimew<100&&PressuremmHgw>20)		//tight
	{
		CuffTight = 1;

		CuffFlag=1;
		CuffOKFlag=0;
	}
}

void	showresults(void)
{
#if 1
	unsigned char i;
	unsigned int TempSYS;
	unsigned int TempDIA;
	unsigned char SYSDeviation;
	unsigned char DIADeviation;
//************************************************************************以下为平均值
	if((SystolicValue1b>99)&&(SystolicValue1b<150)) SYSDeviation=12;
	else{SYSDeviation=15;}
	if(SystolicValue1b<100) SYSDeviation=10;
	if((DiastolicValue>69)&&(DiastolicValue<100)) DIADeviation=8;
	else{DIADeviation=10;}
	if(DiastolicValue<70) DIADeviation=6;
	if(UparmWWFlag)
		{
			SYSDeviation-=3;
			DIADeviation-=2;
		}
	i=0;
//	if(UparmWWFlag==0)
// 		{
			if( LastSYS!=0 && LastSYS!=0 && TimeInterval< 240 && TimeInterval>10 )
				{
					if((LastSYS>SystolicValue1b)&&((LastSYS-SystolicValue1b)<SYSDeviation))
			 			{goto SYSAverageResult;}
					if((LastSYS<SystolicValue1b)&&((SystolicValue1b-LastSYS)<SYSDeviation))
			 			{goto SYSAverageResult;}
				}
			goto CheckDIAAverageResult;
SYSAverageResult:
			TempSYS=SystolicValue1b;
			TempSYS+=LastSYS;
			TempSYS++;
			TempSYS/=2;
			SystolicValue1b=TempSYS;

CheckDIAAverageResult:
			if( LastSYS!=0 && LastSYS!=0 && TimeInterval< 240 && TimeInterval>10 )
				{
					if((LastDIA>DiastolicValue)&&((LastDIA-DiastolicValue)<DIADeviation))
			 			{goto DIAAverageResult;}
					if((LastDIA<DiastolicValue)&&((DiastolicValue-LastDIA)<DIADeviation))
			 			{goto DIAAverageResult;}
				}
			goto NoAverageResult;
DIAAverageResult:
			TempDIA=DiastolicValue;
			TempDIA+=LastDIA;
			TempDIA++;
			TempDIA/=2;
			DiastolicValue=TempDIA;
// 		}

NoAverageResult:
////////////////////////////////////////////////////20121002
	AutoOffTimew=0x0000;

	IsShowPressure = 0;
	IsAlgorithm = 0;
	IsAlgoEnd = 0;
  KeyIn=1;
	BPTestFlag=0;
	DarkAllIcon();
	//if(ConnectFlag&&BTIconEnable) BTIconOn;
	if(!NoTimer){showtime();showdate();TimePointIconOn;}
	BTFlag=0;
	SendMemoryFlag=0;
	YSYFlag=0;
	if(UartType==1||UartType==4||UartType==5)
		{
			SendResult();
			delay(4);
			SendResult();
			delay(4);
			SendResult();
			RXIEnable;
			YSYFlag=0;
		}

	if(UartType==6)
	{
		delay(16);
		SendResult();
	}

	if(UartType==2)
		{
			SendResultTest();
		}

	UserABDisplay();
	ShowVoice();
	mmHgKpaDisplay(SystolicValue1b,DiastolicValue);
    if(PulseRate<MIN_PULSERATE)
    {
        DisplayHalfByte(0x13,PulseTen);/*L*/
        DisplayHalfByte(0x14,PulseSingle);/*o*/
    }
    else if(PulseRate>MAX_PULSERATE)
    {
        DisplayHalfByte(0x11,PulseTen);/*H*/
        DisplayHalfByte(0x12,PulseSingle);/*I*/
    }
	else
    {
        DisplayToPUL(PulseRate);
    }

	BUZZER_EN; //20100924新增结果OK后,BZ长响
	delay(64);
	BUZZER_DIS;
//*************************语音部分
	if(!BLFlag) DPDetect(SystolicValue1b,DiastolicValue);
	if(BPLevelType!=0)
		{ShowWHO(SystolicValue1b,DiastolicValue);}	//20101226新增WHO显示
	if(PADEnable==1)
		{
			if(PADFlag==1)
				{PADIconOn;}
		}
	if(MoveDetect)
	{
		if(MoveFlag) MoveIconOn;
	}
	if(CuffDetect)
	{
        CuffIconOn;
        if(CuffOKFlag==1) 		//20221026 add
		{
			OKIconOn;
		}
		// if(CuffFlag) CuffIconOn;
		// if(CuffOKFlag==1) 		//20221026 add
		// {
		// 	OKIconOn;
		// }
	}
//*************************语音部分
	if(VoiceEnable==1)
		{
			VoiceStop=0;
			if((PulseRate>=MIN_PULSERATE)&&(PulseRate<=MAX_PULSERATE)){i=PulseRate;}
			else{i=0;}
			if(VoiceType==1||VoiceType==14)
			{
				if((VoiceType==1) && (VoiceType2==2)) 		//20230508 CN+MD
				{
//					SoundCommand(0xD5);
//					if(VoiceStop) {VoiceStop=0;goto EXIT;}
					if(mmHgkPaFlag){SoundAllCommand(0x55,SystolicValue1b,DiastolicValue,i);}	//高压是+SYS+毫米汞柱+低压是+DIA+毫米汞柱+每分钟心跳次数是+PUL+次
					else
					{
						if(VoiceFlag==0)
						{
							SoundAllCommand(0xaa,SystolicValue1b,DiastolicValue,i);
						}

					}	//kpa;
					if(VoiceStop) {VoiceStop=0;goto EXIT;}
					if(BPLevelType==1||BPLevelType==3)
					{
						SoundAllCommand(0x66,WHOLevel,0,0);//根据世界卫生组织标准,您的血压正常/正常值偏高/轻度高血压/中度高血压/重度高血压
						if(VoiceStop) {VoiceStop=0;goto EXIT;}
					}
//					if((PADEnable==1)&&(PADFlag==1))
//					{SoundCommand(0xE7);}
				}
                else if(VoiceType==1&&VoiceType2==3)
                {
                    if(mmHgkPaFlag==0)
                    {

                    }
                    else
                    {
                        volume_adjus_china_eng_malay(VoiceLevel);//中语英语马来西亚语音量调节
                        if(mmHgkPaFlag) SoundAllCommand(0x55,SystolicValue1b,DiastolicValue,i);//高压是+SYS+毫米汞柱+低压是+DIA+毫米汞柱+每分钟心跳次数是+PUL+次
                        if(VoiceStop) {VoiceStop=0;goto EXIT;}
                        if(BPLevelType==1){
                            delay(60);//新需求 who前加延时 0.8s
                            SoundAllCommand(0x66,WHOLevel,0,0);//根据世界卫生组织标准,您的血压正常/正常值偏高/轻度高血压/中度高血压/重度高血压
                            if(VoiceStop) {VoiceStop=0;goto EXIT;}
                            if(WHOLevel>=4){SoundCommand(0xD7);}	//D7H 若连续几天都维持这数值请恰询您的医师
                            if(VoiceStop) {VoiceStop=0;goto EXIT;}
                        }
                        if((PADEnable==1)&&(PADFlag==1))
                            {SoundCommand(0xD9);}		//D9H请注意,此次量测有侦测到心率不齐，请按指示重新量测.如连续三次均测出心率不齐，请恰询您的医师
                        if(VoiceStop) {VoiceStop=0;goto EXIT;}
                    }
                }
				else
				{
					SoundCommand(0xD5);
					if(VoiceStop) {VoiceStop=0;goto EXIT;}
					if(mmHgkPaFlag){SoundAllCommand(0x55,SystolicValue1b,DiastolicValue,i);}	//高压是+SYS+毫米汞柱+低压是+DIA+毫米汞柱+每分钟心跳次数是+PUL+次
					else{SoundAllCommand(0xaa,SystolicValue1b,DiastolicValue,i);}	//kpa;
					if(VoiceStop) {VoiceStop=0;goto EXIT;}
					if(BPLevelType==1||BPLevelType==3)
					{
						SoundAllCommand(0x66,WHOLevel,0,0);//根据世界卫生组织标准,您的血压正常/正常值偏高/轻度高血压/中度高血压/重度高血压
						if(VoiceStop) {VoiceStop=0;goto EXIT;}
						if(WHOLevel>=4){SoundCommand(0xe5);}	//若连续几天都维持这数值,请恰询您的医师
						if(VoiceStop) {VoiceStop=0;goto EXIT;}
					}
					if((PADEnable==1)&&(PADFlag==1))
					{SoundCommand(0xE7);}		//请注意,此次量测有侦测到心率不齐,请按指示重新量测.如连续三次均测出心率不齐,请恰询您的医师
				}
			}
			else if(VoiceType>=2&&VoiceType<=4)
			{
				SoundAllCommand(0x11,SystolicValue1b,DiastolicValue,i);	//高压是+SYS+毫米汞柱+低压是+DIA+毫米汞柱+每分钟心跳次数是+PUL+次
				if(VoiceStop) {VoiceStop=0;goto EXIT;}
				if((BPLevelType==1) || (BPLevelType==8))
				{
					if((BPLevelType==8) && FreWho130Flag)	{VoiceStop=0;goto EXIT;}
					SoundAllCommand(0x22,WHOLevel,0,0);//根据世界卫生组织标准,您的血压正常/正常值偏高/轻度高血压/中度高血压/重度高血压
				}
			}
			else if(VoiceType==5)
			{
				SoundAllCommand(0x55,SystolicValue1b,DiastolicValue,i);
				if(VoiceStop) {VoiceStop=0;goto EXIT;}
				if(BPLevelType==1){
					SoundAllCommand(0x66,WHOLevel,0,0);//根据世界卫生组织标准,您的血压正常/正常值偏高/轻度高血压/中度高血压/重度高血压
					if(VoiceStop) {VoiceStop=0;goto EXIT;}
				}
				SoundCommand(0xE9);
			}
			else if(VoiceType==7)
			{
				SoundAllCommand(0x55,SystolicValue1b,DiastolicValue,i);
			}
			else if(VoiceType==6)
			{
				if(VoiceFlag==1&&!mmHgkPaFlag) goto EXIT;
				SoundCommand2(0xD5);
				if(VoiceStop) {VoiceStop=0;goto EXIT;}
				if(mmHgkPaFlag){SoundAllCommand2(0x55,SystolicValue1b,DiastolicValue,i);}	//高压是+SYS+毫米汞柱+低压是+DIA+毫米汞柱+每分钟心跳次数是+PUL+次
				else{SoundAllCommand2(0xaa,SystolicValue1b,DiastolicValue,i);}	//kpa;
				if(VoiceStop) {VoiceStop=0;goto EXIT;}
				if(BPLevelType==1){
					SoundAllCommand2(0x66,WHOLevel,0,0);//根据世界卫生组织标准,您的血压正常/正常值偏高/轻度高血压/中度高血压/重度高血压
					if(VoiceStop) {VoiceStop=0;goto EXIT;}
					if(WHOLevel>=4){SoundCommand2(0xe5);}	//若连续几天都维持这数值,请恰询您的医师
					if(VoiceStop) {VoiceStop=0;goto EXIT;}
				}
				if((PADEnable==1)&&(PADFlag==1))
				{SoundCommand2(0xE7);}		//请注意,此次量测有侦测到心率不齐,请按指示重新量测.如连续三次均测出心率不齐,请恰询您的医师
			}
			else if(VoiceType==8&&VoiceFlag<5)
			{
				SoundFive();
				SoundAllCommand2(0x55,SystolicValue1b,DiastolicValue,i);
				if(VoiceStop) {VoiceStop=0;goto EXIT;}
				if(BPLevelType==1){
					SoundAllCommand2(0x66,WHOLevel,0,0);//根据世界卫生组织标准,您的血压正常/正常值偏高/轻度高血压/中度高血压/重度高血压
					if(VoiceStop) {VoiceStop=0;goto EXIT;}
				}
			}
			else if(VoiceType==9)
			{
				SoundCommand(0xc3);
				if(VoiceStop) {VoiceStop=0;goto EXIT;}
				if(mmHgkPaFlag){SoundAllCommand(0x55,SystolicValue1b,DiastolicValue,i);}
				if(VoiceStop) {VoiceStop=0;goto EXIT;}
				if(BPLevelType==1){
					SoundAllCommand(0x66,WHOLevel,0,0);
					if(VoiceStop) {VoiceStop=0;goto EXIT;}
					if(WHOLevel==4||WHOLevel==3){SoundCommand(0xCE);}
					if(VoiceStop) {VoiceStop=0;goto EXIT;}
				}
			}
			else if(VoiceType==10)	//Khmer
			{
				SoundAllCommand(0x11,SystolicValue1b,DiastolicValue,i);	//your blood pressure is SYS + DIA + PUL
			}
			else if(VoiceType==11)
			{
				SoundAllCommand2(0x44,SystolicValue1b,DiastolicValue,i);	//高压是+SYS+毫米汞柱+低压是+DIA+毫米汞柱+每分钟心跳次数是+PUL+次
				if(VoiceStop) {VoiceStop=0;goto EXIT;}
				if(BPLevelType==1){
					if(WHOLevel<6) SoundAllCommand2(0x55,WHOLevel,0,0);//根据世界卫生组织标准,您的血压正常/正常值偏高/轻度高血压/中度高血压/重度高血压
					else
					{
						SoundCommand2(0xc6);
						if(VoiceStop) {VoiceStop=0;goto EXIT;}
						SoundCommand2(0xc7);
						if(VoiceStop) {VoiceStop=0;goto EXIT;}
						SoundCommand2(0xce);
					}
				}
			}
			else if(VoiceType==12)
			{
				SoundCommand(0xD5);
				if(VoiceStop) {VoiceStop=0;goto EXIT;}
				if(mmHgkPaFlag) SoundAllCommand(0x55,SystolicValue1b,DiastolicValue,i);
				else SoundAllCommand(0xAA,SystolicValue1b,DiastolicValue,i);
				if(VoiceStop) {VoiceStop=0;goto EXIT;}
				SoundWHO(SystolicValue1b,DiastolicValue);
			}
			else if(VoiceType==13&&VoiceLevel>0)
			{
				if(VoiceType>0&&mmHgkPaFlag==0) goto EXIT;
				SoundThree();
				SoundCommand2(0xD2);
				if(VoiceStop) {VoiceStop=0;goto EXIT;}
				SoundThree();
				if(mmHgkPaFlag) SoundAllCommand2(0x55,SystolicValue1b,DiastolicValue,i);
				else SoundAllCommand2(0xAA,SystolicValue1b,DiastolicValue,i);
				if(VoiceStop) {VoiceStop=0;goto EXIT;}
				if(BPLevelType==1){
					SoundThree();
					SoundAllCommand2(0x66,WHOLevel,0,0);//根据世界卫生组织标准,您的血压正常/正常值偏高/轻度高血压/中度高血压/重度高血压
					if(VoiceStop) {VoiceStop=0;goto EXIT;}
					SoundThree();
					if(WHOLevel==5&&(VoiceType==0)){SoundCommand(0xE2);}
					if(WHOLevel==3&&(VoiceType>0)){SoundCommand(0xE2);}
					if(VoiceStop) {VoiceStop=0;goto EXIT;}
				}
			}
		}
//*************************语音部分
EXIT:
	if(VoiceEnable) SoundOff();
	TimeInterval=10;				//开始计时.//20121002
	LastSYS= SystolicValue1b;		//20121002
	LastDIA= DiastolicValue;		//20121002
	KeyModeFlag.b=0;
	do
		{
			delay(1);
			showtime();
			showdate();
			if(AutoTestFlag)
			{
				if(AutoOffTime2b>0) break;
			}
			if(UartType==5&&WorkMode==1) break;

			if(AutoOffTimew>AUTOOFFTIME&&!AllTimeFlag) break;

			if(KeyNumber==11)
			{
				if(!KEY_POWER) break;
				if(!KEY_MEMORYUP||!KEY_MEMORYDOWN) {MemoryKeyFlag=1;break;}
				if(LongSetFlag) {SetKeyFlag=1;break;}
			}
			else if(KeyNumber==12)
			{
				if(!KEY_POWER) break;
				if(!KEY_TIME) {MemoryKeyFlag=1;break;}
			}
			else
			{
				if(!KeyIn) break;
			}

		}while(IsPowerOn&&!BTFlag&&!YSYFlag&&!SendMemoryFlag);
	IsPowerOn=0;
	DarkAllIcon();
	if(YSYFlag)
	{
		YSYFlag=0;
		IsPowerOn=1;
		for(N=0;N<YSYCount;N++)
		{
			Relax(FSTime);
			if(!IsPowerOn) break;
			PumptoTarget(YSYPress,YPTime);
			if(!IsPowerOn) break;
		}
	}
	IsPowerOn=0;
	//OUT_VALVE=0;
	OUT_VALVE(0);
	PUMPPWM_DIS;
#endif
}



void	resultdata(void)
{
	MemoryMode=1;
	ResultDataS = SystolicValue1b;
	ResultDataD = DiastolicValue;
	ResultDataH = PulseRate;

	EEPROMin = 0;
	readM24L16();
	MemoryEndIndex=inbyte[0];
	MemoryEndIndex<<=8;
	MemoryEndIndex+=inbyte[1];
	if(MemoryEndIndex > MemorySet) MemoryFull = 1;

	ResultDataDA = Day+(Month&0x03)*64;	//M0+data;
    ResultDataHO = Hour+(Month&0x0c)*16;
    ResultDataMI = Minute;
    if(PADFlag==1)
    	{ResultDataMI|=0x80;}		//20110306增加如果本笔记忆有PAD则写入Memory.

    if (CuffDetect)
    {
        if (CuffOKFlag == 1)
        {
            ResultDataMI |= 0x40;
        } // 2022年12月14日 CuffOKFlag 写入记忆
    }

    if (MoveDetect)
    {
        if (MoveFlag == 1)
        {
            ResultDataDA |= 0x20;
        } // 2022年12月14日 MoveFlag 写入记忆
    }

	savetomemory();

	MemoryMode=0;
}


void tomemorykeyinX(uint16 MemoryIndex)
{
//	unsigned char i;
	MemoryMode=1;
	DarkAllIcon();
	EEPROMin= MemoryIndex;
	readM24L16();
	PulseRam[1].b[0] = inbyte[0];  	/*systolic  pressure*/
	PulseRam[2].b[0] = inbyte[1];  	/*diastolic  pressure*/
	PulseRam[3].b[0] = inbyte[2];  	/*heart rate*/
    PulseRam[9].b[0] = inbyte[3];  	/*M0_data*/
	PulseRam[6].b[0] = inbyte[4];  	/*M1_hour*/
//	PulseRam[7].b[0] = inbyte[5];  	/*Minute*/
 	PulseRam[7].b[0] = (inbyte[5]&0x3f);  	/*Minute 把PAD符号OK符号去掉*/
	PulseRam[8].b[0] = (inbyte[6]&0x80);
	PulseRam[4].b[0] = (PulseRam[9].b[0]&0xc0)/64 + (PulseRam[6].b[0]&0xc0)/16;/*month*/
	PulseRam[5].b[0] = PulseRam[9].b[0]&0x1f;    //*date 把MOVE符号去掉
	PulseRam[6].b[0] &= 0x3f;  	/*hour*/

	MemoryIconOn;//MarkMEMORY = 1;			//MR icon display

    if (CuffDetect)
    {
        if((inbyte[5] & 0x40)==0x40)//CuffOKFlag 存放位置
            CuffOKFlag = 1;
            // CuffIconOn;
        else
            CuffOKFlag = 0;
            // CuffIconOff;
    }

    if (MoveDetect)
    {
        if((inbyte[3] & 0x20)==0x20)//MoveFlag 存放位置
            MoveFlag = 1;
            // MoveIconOn;
        else
            MoveFlag = 0;
            // MoveIconOff;
    }

	if((inbyte[5] & 0x80)==0x80)
		{PADFlag=1;}
	else
		{PADFlag=0;}

}

void tomemoryMemorySenevAVg(unsigned int MemoryIndex1)
{
	unsigned char index_value;

	SysMeanEnd=DiaMeanEnd=PulseMeanEnd=0;

	index_value = MemoryIndex1 -1 ;


	if(index_value == 0)
	{
		if(MemoryFull )	 index_value = MemorySet;
		else   index_value =MemoryEndIndexBackup;
	}

	if(MemoryIndex == 1)
	{
/*
		DisplayHalfByte(0x10,LastSysMemorySetHundred);
		DisplayHalfByte(0x10,LastSysMemorySetTen);
		DisplayHalfByte(0,LastSysMemorySetSingle);

		DisplayHalfByte(0x10,LastDiaMemorySetHundred);
		DisplayHalfByte(0x10,LastDiaMemorySetTen);
		DisplayHalfByte(0,LastDiaMemorySetSingle);

		DiaComparevalue = 0;
		SysComparevalue = 0;
*/
	}
	else
	{
		if(MemoryFull==0)
		{
			if(AverageSet>index_value)
			{AverageSet=index_value;}
		}
		else if(MemoryFull==1)
		{
			if(MemoryIndex < 8)
				AverageSet = MemoryIndex - 1;

		}

		if(((index_value>0)||(MemoryFull==1))&&ShowMean)		//如果有记忆值大于1,且有显示平均值功能,
		{
			for(i=0;i<AverageSet;i++)
			{
				EEPROMin = index_value;
				readM24L16();
				SysMeanEnd += inbyte[0];
				DiaMeanEnd += inbyte[1];
				PulseMeanEnd += inbyte[2];

				index_value--;
				if(index_value==0){index_value = MemorySet;}
			}

			SysMeanEnd /=AverageSet;
			DiaMeanEnd /= AverageSet;
			PulseMeanEnd /= AverageSet;
		}
/*
		if(SysMeanEnd<100) DisplayHalfByte(0x10,LastSysMemorySetHundred);	//显示空
		else DisplayHalfByte(SysMeanEnd/100,LastSysMemorySetHundred);

		if(SysMeanEnd<10&&mmHgkPaFlag){DisplayHalfByte(0x10,LastSysMemorySetTen);}//显示空
		else DisplayHalfByte((SysMeanEnd/10)%10,LastSysMemorySetTen);

		DisplayHalfByte(((SysMeanEnd%100)%10),LastSysMemorySetSingle);

		if(DiaMeanEnd<100) DisplayHalfByte(0x10,LastDiaMemorySetHundred);	//显示空
		else DisplayHalfByte(DiaMeanEnd/100,LastDiaMemorySetHundred);

		if(DiaMeanEnd<10&&mmHgkPaFlag){DisplayHalfByte(0x10,LastDiaMemorySetTen);}//显示空
		else DisplayHalfByte((DiaMeanEnd/10)%10,LastDiaMemorySetTen);

		DisplayHalfByte(((DiaMeanEnd%100)%10),LastDiaMemorySetSingle);

		DiaComparevalue = DiaMeanEnd;
		SysComparevalue = SysMeanEnd;
*/
	}
//		AverageSet = 7;
}

void nopdelay(void)
{
	uint32 x=delaytest;
	while(x>0)
	{
		x--;
		nop4();
	}
}

